I am a guy who always likes to search online to get the answer. So StackOverflow is my favorite website. But after tens times’s search, you find you always search the same questions sometimes. Here I write down useful Git commands which I use most.
When you finish installing Git, you have to configure it to push your personal information on your GitHub or other git server.
// no "--global" means for one Git repo, with "--global" means for one user, with "--system" means for the whole system(here, you need to use sudo) git config --global user.name "Your Name" git config --global user.email "firstname.lastname@example.org"
If you want to check your configuration status, you can use list. Of course, you can go to ~/.git/config to see your local folder’s configuration and ~/.gitconfig to check global Git configuration.
git config --list
If this is not your first time configuration, you can use amend to change it.
git commit --amend --author='Your Name <email@example.com>'
If you want to revert to a special commit based on commitID, you can use reset.
git reset --hard c14809fa
If you want to merge multiple commits to one, use this:
git rebase -i <unchanged commitID>
Setting your branch to exactly match the remote branch can be done in two steps:
git fetch origin git reset --hard origin/master
If you want to compare your local Git repo with remote, you can use diff.
git diff <local branch> <remote-tracking branch> // For example
git diff master origin/master, or
git diff featureA origin/next
If you want to rename a local Git branch,
git branch -m <oldname> <newname>
If you want to rename the current branch, you can simply do:
git branch -m <newname>