1. Tracking branch vs Remote tracking branch
http://www.gitguys.com/topics/tracking-branches-and-remote-tracking-branches/
2. Reset local master to track remote master
Method 1:
#Rename your local master branch
git branch -m master _old_master_branch_
#Create a new master branch from a remote source
git checkout -b master origin/master
Method 2:
git fetch remoteSource
git reset --hard remoteSource/master
For method 2, you are throwing away all your changes in current master branch.
—————————————Notes for commands—————————————————————
- git hash-object [file_name] // See the full sha1 hash of the file
- git ls-files --stage // show list of files in (staging area)/(git index)
- git ls-files --stage --abbrev // abbreviate the hash
- git show [file_hash_code] //show the content of the file
- git cat-file -p HEAD // display the most recent commit and find the git tree it refers to
- git ls-tree [tree_hash_code] - -abbrev // display the content of the tree
- git tag [tag_name] -m “Input your tag message here”// tag the current state of the repository
- git cat-file -p [tag_name] // display details of a tag
- git tag -m “Input your tag message here” [tag_name] [hash_code_for_commit_you_wanna_tag]
- git tag -l // get a list of tags
- git checkout [tag_name] // check out files that were tag with [tag_name]
- git ls-files // Show what files are in the git index
- git mv README readme // rename a file in the index and the working directory from README to readme
- git rm [file_name] --cached// Remove a file from the index while keep it at the actual location
- git diff --cached // Differences between the index and the most recent commit
- gt diff // Differences between the working directory and the index
- git diff HEAD // Differences between the working directory and the most recent commit
- git show // Shows both the commit and the difference between the commit and any parent commit
- git show HEAD~ //Show the commit from the parent of the HEAD
- git show HEAD~2 //Show the commit from the grandparent of the HEAD
- git show [hash_code_for_commit]
- git branch -d [branch_name] // Delete a branch
- git show-branch // Show the branches and the commit history. A “*”begins the line if this branch is the current branch. A “!”begins the line if this branch is not the current branch. The branch name is reported, in [brackets]. The branch’s most recent commit is shown. Below the “—“ line is the commit history. Commits before the common ancestor are shown, until the point where the branches have a common ancestor.
- git stash // Temporarily stashing your work
- git show [branch_name]:[file_name] // See the content of [file_name] from branch [branch_name]
- When we have conflicts when running git merge, command 27 and 28 are there to help.
- git ls-files -u // Show which files need merging. 1: The “common ancestor”of the file. 2: The version from the current branch. 3: The version from the other branch.
- git show :1:[file_name] // show file in stage 1
- git remote // List the names of remote repositories
- git push origin master // push the branch names master to the remote repository named origin
- git pull origin [branch_name] // When you are on branch [branch_name], you can pull the newest changes from remote repo by this command
- git branch --set-upstream [branch_name] origin/[branch_name] // Do this once to avoid typing command 31 every time for pull
- git remote prune origin // remove all tracking branches that have been deleted in the remote repo. But it won’t delete the actual local branch
- git branch --track [branch_name] origin/[branch_name] // Same result as 34
- git branch -r // Show remote tracking branches
- git branch -a //Show all branches
- git remote -v //Show basic info about the default remote
- git remote show origin //Show a lot about a remote
No comments:
Post a Comment