DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for Easy-Breezy Clarifications of Git Commands
S.M. Faizul Islam Fair
S.M. Faizul Islam Fair

Posted on

Easy-Breezy Clarifications of Git Commands

Yes, yes, that's right guys! This is it, this is the perfect place to get a grasp on some tight git commands. Pretty explanations in just 1 or 2 sentences. So, let's get started.....

To setup username globally

git config --global user.name "username"
Enter fullscreen mode Exit fullscreen mode

To setup email globally

git config --global user.email "email"
Enter fullscreen mode Exit fullscreen mode

To change username globally

git config --global user.name "username"
Enter fullscreen mode Exit fullscreen mode

To change email globally

git config --global user.email "email"
Enter fullscreen mode Exit fullscreen mode

To check if the setup is complete

git config --list
Enter fullscreen mode Exit fullscreen mode

To exit the list

press 'q'(just q)
Enter fullscreen mode Exit fullscreen mode

To see the username

git config user.name
Enter fullscreen mode Exit fullscreen mode

To see the email

git config user.email
Enter fullscreen mode Exit fullscreen mode

To delete branch locally,

git branch -D branch_name
Enter fullscreen mode Exit fullscreen mode

To delete branch remotely,

git push origin --delete branch_name
Enter fullscreen mode Exit fullscreen mode

To remove a specific staged file (only added/staged, not committed) or unstage

git rm --cached file_name(with extension) 
Enter fullscreen mode Exit fullscreen mode

or,

git reset file_name(with extension)
Enter fullscreen mode Exit fullscreen mode

To remove all staged files (only added/staged, not committed) or unstage

git reset HEAD
Enter fullscreen mode Exit fullscreen mode

To remove all staged changes (even from files) and staged files(only added/staged, not committed) or unstage

git reset --hard HEAD
Enter fullscreen mode Exit fullscreen mode

To exit from git log press 'q' (just q)

To view all commits with ids in a clean way

git log --pretty=oneline
Enter fullscreen mode Exit fullscreen mode

To view all commits with ids in a clean way (shorter version)

git log --oneline
Enter fullscreen mode Exit fullscreen mode

To display changes between a specific commit and current head

git diff commit_id
Enter fullscreen mode Exit fullscreen mode

To abort merge after getting conflict message

git merge --abort
Enter fullscreen mode Exit fullscreen mode

To bring in changes from a specific commit from another branch and commit(same repository)

git cherry-pick commit_id
Enter fullscreen mode Exit fullscreen mode

To bring in changes from a specific commit from another branch and only add but not commit(same repository)

git cherry-pick commit_id -n
Enter fullscreen mode Exit fullscreen mode

To not lose changes by not committing yet and moving to another branch to work on something

git stash <br>
Enter fullscreen mode Exit fullscreen mode

or,

git stash -u 
Enter fullscreen mode Exit fullscreen mode

and then to apply changes after coming back later

git stash apply index_number(0)
Enter fullscreen mode Exit fullscreen mode

To save stash with a custom message

git stash push -m "message_name"
Enter fullscreen mode Exit fullscreen mode

To change name of most recent commit that hasn't been pushed to remote repo yet

git commit --amend -m "new commit message"
Enter fullscreen mode Exit fullscreen mode

To change name of most recent commit that has been pushed to remote repo

git commit --amend -m "new commit message"
Enter fullscreen mode Exit fullscreen mode

Plus

git push --force
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

12 APIs That You Will Love

>> Check out this classic DEV post <<