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"
To setup email globally
git config --global user.email "email"
To change username globally
git config --global user.name "username"
To change email globally
git config --global user.email "email"
To check if the setup is complete
git config --list
To exit the list
press 'q'(just q)
To see the username
git config user.name
To see the email
git config user.email
To delete branch locally,
git branch -D branch_name
To delete branch remotely,
git push origin --delete branch_name
To remove a specific staged file (only added/staged, not committed) or unstage
git rm --cached file_name(with extension)
or,
git reset file_name(with extension)
To remove all staged files (only added/staged, not committed) or unstage
git reset HEAD
To remove all staged changes (even from files) and staged files(only added/staged, not committed) or unstage
git reset --hard HEAD
To exit from git log press 'q' (just q)
To view all commits with ids in a clean way
git log --pretty=oneline
To view all commits with ids in a clean way (shorter version)
git log --oneline
To display changes between a specific commit and current head
git diff commit_id
To abort merge after getting conflict message
git merge --abort
To bring in changes from a specific commit from another branch and commit(same repository)
git cherry-pick commit_id
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
To not lose changes by not committing yet and moving to another branch to work on something
git stash <br>
or,
git stash -u
and then to apply changes after coming back later
git stash apply index_number(0)
To save stash with a custom message
git stash push -m "message_name"
To change name of most recent commit that hasn't been pushed to remote repo yet
git commit --amend -m "new commit message"
To change name of most recent commit that has been pushed to remote repo
git commit --amend -m "new commit message"
Plus
git push --force
To forcefully revert back to the state of the latest commit, discarding any local changes and disregarding any conflicts or warnings
git checkout HEAD~ --force
To move HEAD to a particular commit, push to repo and pull to master branch
git checkout commit_id
git add .
git commit -m "commit message"
git push origin HEAD:master --force
Plus
git checkout master
git pull
Top comments (0)