DEV Community

Rina
Rina

Posted on

Top 10 Git Commands I Use Every Day

Over the years, I've found myself relying on a core set of Git commands on a daily basis. These commands help me manage code changes, synchronize with team members, and maintain a clean project history.

Here's a rundown of the top 10 Git commands that are indispensable in my daily workflow.

1. git clone

Before you can work on a project, you need to get it onto your local machine. The git clone command does just that by copying an existing Git repository from a remote location to your local machine.

git clone <repository-url>
Enter fullscreen mode Exit fullscreen mode

2. git status

Once you've started making changes, it's crucial to keep track of your work. The git status command provides a summary of which files have been modified, which are staged for commit, and which are not being tracked by Git.

git status
Enter fullscreen mode Exit fullscreen mode

3. git add

When you're ready to save changes in Git, you first need to stage them using the git add command. This command updates the index with the current content found in the working tree, to prepare the content staged for the next commit.

git add <file-or-directory>
Enter fullscreen mode Exit fullscreen mode

4. git commit

Committing is like taking a snapshot of your project's currently staged changes. The git commit command captures your changes in a new commit along with a log message from the user describing those changes.

git commit -m "Your commit message here"
Enter fullscreen mode Exit fullscreen mode

5. git push

After committing your changes locally, you'll want to share them with your team or update the remote repository. The git push command uploads your commits to the remote repository.

git push origin <branch-name>
Enter fullscreen mode Exit fullscreen mode

6. git pull

To synchronize your local repository with the remote, use the git pull command. It fetches and merges changes on the remote server to your working directory.

git pull origin <branch-name>
Enter fullscreen mode Exit fullscreen mode

7. git branch

Working on a new feature or fix? The git branch command helps you manage your branches and ensures that you're working in the right context.

git branch <branch-name>
Enter fullscreen mode Exit fullscreen mode

8. git checkout

Switching between branches is a common task. The git checkout command lets you navigate to different branches in your repository.

git checkout <branch-name>
Enter fullscreen mode Exit fullscreen mode

9. git merge

Once your feature or fix is ready, you'll need to merge your branch back into the main branch. The git merge command combines the history of the specified branch into your current branch.

git merge <branch-name>
Enter fullscreen mode Exit fullscreen mode

10. git log

To view the commit history of your project, the git log command is invaluable. It shows the chronological commit history for the current branch.

git log
Enter fullscreen mode Exit fullscreen mode

Incorporating these commands into your daily workflow can significantly improve your productivity and collaboration efforts on any Git-based project.




Besides all the commands above, I will check [dev resources](https://cheatsheet.md) in case I forget something.

Hope this tip helps!
Enter fullscreen mode Exit fullscreen mode

Top comments (0)