# Fetch all the branches of that remote into remote-tracking branches, # such as upstream/master:
git fetch upstream
# Make sure that you're on your master branch:
git checkout master
# Rewrite your master branch so that any commits of yours that # aren't already in upstream/master are replayed on top of that # other branch:
git rebase upstream/master
git push -f origin master
git branch
1
git show-branch -a
Show branches and their commits
1
git branch <branch>
Create a new branch called . This does not check out the new branch.
1
git branch -d <branch>
Delete the specified branch.
1
git branch -D <branch>
Force delete the specified branch, even if it has unmerged changes.
1
git branch -m <branch>
Rename the current branch to <branch>.
1 2
git checkout $branch2 git merge $branch1
Merge branch1 into branch2.
1
warning: refname 'HEAD' is ambiguous.
1 2
git branch -m HEAD temp git branch -d temp
git checkout
Give up the current modification and go back to the last commit
1
git checkout -- .
1 2 3 4 5 6 7
git log --oneline
b7119f2 Continue doing crazy things 872fa7e Try something crazy a1e8fb5 Make some important changes to hello.py 435b61d Create hello.py 9773e52 Initial import
You can find the ID of the revision you want to see.
1 2
git checkout a1e8fb5 git checkout master
Nothing you do in here will be saved in your repository.
1 2
git checkout a1e8fb5 hello.py git checkout HEAD hello.py
Unlike checking out a commit, this does affect the current state of your project.
1 2
git status HEAD detached From 91ea20b
1 2 3 4 5
git checkout source error: Your local changes to the following files would be overwritten by checkout: source/_posts/2016-02-25-github.markdown Please, commit your changes or stash them before you can switch branches. Aborting
1 2
git stash git checkout source
git clean
1
git clean -n
This will show you which files are going to be removed without actually doing it.
1
git clean -f
Remove untracked files from the current directory.
1
git clean -f <path>
Remove untracked files, but limit the operation to the specified path.
1
git clean -df
Remove untracked files and untracked directories from the current directory.
1
git clean -xf
Remove untracked files from the current directory as well as any files that Git usually ignores.
git clone
If you clone a repository, the default branch you have is whatever the remote’s HEAD points to (HEAD is actually a symbolic ref that points to a branch name).
A symbolic ref is a regular file that stores a string that begins with ref: refs/. For example, your .git/HEAD is a regular file whose contents is ref: refs/heads/master.
HEAD@{1} is always last value of HEAD, ORIG_HEAD is last value of HEAD before dangerous operation.
git commit
1
git commit --amend
Combine the staged changes with the previous commit and replace the previous commit with the resulting snapshot.
1
git commit -a
Commit all your local changes. (like git add . followed by git commit)
The git rm command will allows you to remote a file from git control. The –cached option to git remove allows you to leave it on your hard drive.
git stash
1 2 3 4 5
git stash git stash list git stash pop git stash clear git stash drop
fileMode
100644: normal file
100755: executable file
120000: symbolic link
The mode is taken from normal UNIX modes but is much less flexible – these three modes are the only ones that are valid for files (blobs) in Git (although other modes are used for directories and submodules).
The 6 digits show the file mode using the classical UNIX notations. First two digits show file type, the third one is about set-uid/set-gid/sticky bits, and you know the last three. 4\2\1 is just r\w\x.
1
man 2 stat
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
S_IFLNK 0120000 symbolic link S_IFREG 0100000 regular file
S_IRWXU 00700 mask for file owner permissions S_IRUSR 00400 owner has read permission S_IWUSR 00200 owner has write permission S_IXUSR 00100 owner has execute permission S_IRWXG 00070 mask for group permissions S_IRGRP 00040 group has read permission S_IWGRP 00020 group has write permission S_IXGRP 00010 group has execute permission S_IRWXO 00007 mask for permissions for others (not in group) S_IROTH 00004 others have read permission S_IWOTH 00002 others have write permission S_IXOTH 00001 others have execute permission