Sitemap
Signor Dev

Signor Dev

Software Developer | Technical Writer

Introduction to Basic Git Command Prompts

3 min readSep 20, 2023

--

Ready to take control of your coding journey? Git is a powerful tool that can streamline your development process and help you collaborate seamlessly with other developers. 🤝

Press enter or click to view image in full size
Git
Git

As a developer, mastering version control is essential for efficient collaboration and project management.

Get Signor Dev’s stories in your inbox

Join Medium for free to get updates from this writer.

Git is a widely-used distributed version control system, and a fundamental tool in the developer’s toolkit. While Git can be managed through graphical user interfaces (GUIs), learning and using Git command prompts can offer greater control, flexibility, and speed in managing your projects. In this article, we’ll look into some Git command prompts, providing detailed examples for easy understanding.

Setting Up Git

Before you start using Git, you need to set it up on your machine. Here’s how:

Installing Git

If you haven’t already installed Git, download it from the official website (https://git-scm.com/downloads) and follow the installation instructions for your operating system.

Configuring Your Identity

Once Git is installed, you should configure your identity by setting your name and email address:

git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"

Creating a New Repository

To start using Git for a new project, you need to create a Git repository. Navigate to the project’s directory and run the following commands:

mkdir my_project
cd my_project
git init

0.1 Basic Git Commands

Checking the Repository Status

You can check the status of your repository to see which files have been modified or added:

git status

Adding Files to the Staging Area

Before committing changes, you should stage the files you want to include in the next commit:

git add main.js          # Stage a specific file
git add . # Stage all changes in the current directory

Committing Changes

Once your changes are staged, commit them with a meaningful message:

git commit -m "Add initial project files"

Pushing to a Branch

Once they are committed, choose a branch you want to push your repo to:

git branch -M <branch_name>

Adding to a Remote Repository

After choosing a branch, add your project to a remote repository this way:

git remote add origin https://github.com/username/repo.git

Pushing Project

To push your project to a remote repository, use this command:

git push -u origin <branch_name>

0.2 Branching and Merging

Branching allows you to work on different features or bug fixes simultaneously. Here’s how to create and merge branches:

Creating a New Branch

Create a new branch for a specific feature or task:

git branch <branch_name>      # Create a new branch
git checkout <branch_name> # Switch to the new branch

Merging Branches

When you’re done with your changes on a branch, merge it back into the main branch:

git checkout main            # Switch to the main branch
git merge <branch_name> # Merge the new_feature branch into main

0.3 Remote Repositories

Collaboration often involves remote repositories hosted on platforms like GitHub or GitLab. Here’s how to work with remote repositories:

Cloning a Remote Repository

Clone a remote repository to your local machine:

git clone https://github.com/username/repo.git

Pulling Changes

Fetch and merge the latest changes from a remote repository:

git pull origin main       # Fetch and merge changes from the main branch

Pushing Changes

Push your local changes to a remote repository:

git push origin main   # Push changes from the main branch to the remote repository

0.4 Resolving Conflicts

Conflicts can arise when multiple contributors edit the same part of a file. Resolve conflicts with these commands:

Checking for Conflicts

Check for conflicts in your working directory:

git status

Resolving Conflicts

Edit the conflicting file to resolve the conflicts, then add and commit the changes:

git add conflicted_file.txt
git commit -m "Resolve conflicts"

0.5 Git History and Logs

You can view the history of commits and logs using the following commands:

Viewing Commit History

View the commit history, including commit messages and author information:

git log

Viewing Diffs

View the differences between commits:

git diff commit1 commit2

Conclusion

Mastering Git command prompts is a valuable skill for developers. It offers control, flexibility, and efficiency in managing version control for your projects. By following the examples and commands in this article, you can become proficient in using Git and elevate your development workflow to the next level. Git’s power lies in its simplicity and versatility, making it an essential tool for any developer.

--

--

Signor Dev
Signor Dev