Difference between revisions of "My Git notes"

From Zheyong Fan
Jump to navigation Jump to search
 
Line 61: Line 61:
 
git push origin HEAD
 
git push origin HEAD
 
git push origin HEAD:users/user_name/branch_name
 
git push origin HEAD:users/user_name/branch_name
 +
</pre>
 +
 +
* Want to update the current branch from master?
 +
<pre>
 +
git push origin HEAD:users/user_name/branch_name
 +
git checkout master
 +
git pull
 +
git checkout branch_name
 +
git merge master
 
</pre>
 
</pre>

Latest revision as of 08:38, 20 May 2020

  • Check the current status:
git status
  • Create a new branch from master:
git branch my_branch_1
  • Switch to the new branch
git checkout my_branch_1
  • The above two steps can be combined:
git checkout -b my_branch_1
  • Exit the current branch and back to the master branch:
git checkout master
  • Check if you are behind the master:
git fetch
git status
  • If you are behind, update it:
git pull
  • Add changes to prepare for a commit
git add <file_name> # add changes in a file
git add . # add changes in all the files within the current directory (recursively)


  • Discard changes
git restore --staged <file_name>
  • Make a commit:
git commit -m "some comments"
  • Check the difference introduced in the last commit:
git show HEAD~<n> # n = 0, 1, 2, ...
  • Push the current branch to the same name on the remote:
git push origin HEAD
git push origin HEAD:users/user_name/branch_name
  • Want to update the current branch from master?
git push origin HEAD:users/user_name/branch_name
git checkout master
git pull
git checkout branch_name
git merge master