# list all the configured values
git config --list# Set username & email for git globally
git config --global user.name "Progressive Programmer"
git config --global user.email "progressive@gmail.com"# Set committer name & email for git
git config --global committer.name "Programmer"
git config --global committer.email "programmer@gmail.com"
Create a new Repository
# Create a new folder and initialize git repo
git init name
# Clone a remote repo in your local system
git clone url_of_repo
Add files/folders to Staging Area
# Adds mentioned file/folder to the staging area
git add hello.py
# Adds all the files and folders in the current directory
git add .
# Opens the file and let you choose the portion to be added for next commit
git add -p hello.py
Commit Changes
# Commit a snapshot of staged changes
git commit
# Commit a snapshot of changes in the working directory.
git commit -a# Shortcut for commit with a commit message
git commit -m "commit message"
Git Branching
# Create a new branch
git branch crazy_experiment
# List all branches
git branch
# List both remote and local branches
git branch -a# List only branches that match the pattern mentioned
git branch --list 'pattern here'
Switch | Delete | Rename Branch
# Move to different branches
git checkout branch_name
git switch branch_name
# Shortcut to create a new branch and switch to the branch
git switch -cnew_branch_name
git checkout -bnew_branch_name
# Delete the given branch
git branch -dtrash
# Force delete the given branch
git branch -Dtrash
# Rename the current branch
git branch -mnew_name
Merge Branch
# Merge given branch name with the working branch
git merge branch_name
# Continue merger after conflict resolution
git merge --continue
Check Status
# Shows the working tree status
git status
# Shows status of working tree in a short format
git status --short# Shows status of branch in a short format
git status --branch
Remote Repository
# Lists remote repo name and url(fetch/push)
git remote -v# Add a remote repository with local repository
git remote add origin url_remote_repo
# Remove the remote repo with given name
git remote remove repo_name
# Rename the remote repo with given name
git remote rename old_name new_name
# Updates remote repo with local repo
git push
I hope this helps !!ππ
Which is your favorite git command??
Don't forget to drop your thoughts and feedback in the comment section. Also, feel free to suggest any addition to this list..
I am a professional DevOps Engineer with a demonstrated history of working in the internet industry. I am an avid Linux lover and supporter of the open-source movement philosophy.
Thanks Bobby, fortunately, I have read that post and it was a brilliantly explained one. You are quite active in Devdojo and I have been following your posts since I joined Devdojo. And I must say there's a lot that I gained from your posts.
On the funny side, It's usually just three writers that pop up in devdojo's top reads- Tony Lea, Kim Hallberg and yours π !!
I am humbly attempting to share those learning aspects of programming that I found difficult to understand, Git is one of them.
I am a professional DevOps Engineer with a demonstrated history of working in the internet industry. I am an avid Linux lover and supporter of the open-source movement philosophy.
Here's the link to my Devdojo profile : devdojo.com/progressiveprogrammer
π I'll be glad to get feedback on the content. There isn't much content yet but I am working on sharing more of what I am learning currently..
I am a professional DevOps Engineer with a demonstrated history of working in the internet industry. I am an avid Linux lover and supporter of the open-source movement philosophy.
Your posts are looking great! Well done and keep it up! π
One feedback that I have is, you can add the text along with the images, this is good for people who might not be able to see the images for a variety of reasons.
But besides that great job with the images and the content π
This is such a great overview for those new to Git, and a useful cheatsheet for everyone! Thanks for sharing this. One cool addition that would be super useful to new devs would be how to change the remote URL of a git repo.
Thanks Esin, I am glad it's helpful and I am working on sharing more of these to help fellow programmers. i'll surely add how to change remote URL as well. thanks for the addition.
Top comments (8)
Great post! Well done!
I wrote a similar one which goes through the top git commands that you should know!
Thanks Bobby, fortunately, I have read that post and it was a brilliantly explained one. You are quite active in Devdojo and I have been following your posts since I joined Devdojo. And I must say there's a lot that I gained from your posts.
On the funny side, It's usually just three writers that pop up in devdojo's top reads- Tony Lea, Kim Hallberg and yours π !!
I am humbly attempting to share those learning aspects of programming that I found difficult to understand, Git is one of them.
Thanks again for the appreciationππ½
Hey Aman!
Ah thank you for the nice feedback π and happy to hear that you are on DevDojo too!
Yea, you've got a good point there. Can you share your profile link? I would love to go through your posts! π
Thanks Bobby,
Here's the link to my Devdojo profile : devdojo.com/progressiveprogrammer
π I'll be glad to get feedback on the content. There isn't much content yet but I am working on sharing more of what I am learning currently..
Hey Aman,
Your posts are looking great! Well done and keep it up! π
One feedback that I have is, you can add the text along with the images, this is good for people who might not be able to see the images for a variety of reasons.
But besides that great job with the images and the content π
This is such a great overview for those new to Git, and a useful cheatsheet for everyone! Thanks for sharing this. One cool addition that would be super useful to new devs would be how to change the remote URL of a git repo.
Thanks Esin, I am glad it's helpful and I am working on sharing more of these to help fellow programmers. i'll surely add how to change remote URL as well. thanks for the addition.
πππ
Feel free to suggest addition to this list of git commands !!!