Check out my git flowchart. This should cover basic use.
##Branching ###To Create a new branch
git branch
-> make sure you are on the branch (master most of the time) from which you want to branch offgit pull
-> to make sure you are up to date before creating a new branchgit checkout -b <name of your branch>
-> create your new branch and switch to itgit push origin <name of your branch>
-> to make sure other people can see it on githubgit branch --set-upstream-to=origin/<name of your branch> <name of your branch>
-> set tracking to the remote branch.
###Whenever you want to know which branch you are on use the command
git branch
-> list the available branchesgit checkout 'branchname'
-> switch to the branch named 'branchname'
git config --global push.default current
This is important when working on a branch because otherwise git will complain that your master is behind when trying to push
When you are done on a branch you have probably closed an issue. By including the text close #23 in the commit message, the commit automatically closes issue 23 when pushed to github.
After you are content with the changes you made (and have tested them) it is time to merge back into the master. The correct way to do this is as follows:
git pull origin master
-> Pull in the changes on the master into the branch you are working on. Note: pulling in the master will likely result in conflicts, resolve these conflicts and commit the changesgit commit
git push
-> push the changes on the branch back to github.git checkout master
-> make the master branch your active branchgit pull
- -> pull in latest changes on the master
git merge <name of your branch>
-> merges the branch into the mastergit push
-> you are done, the changes should be incorporated in the master
If there is a conflict between two files there are two ways to resolve this. The preferred way is to perform a manual merge. If this is not possible it is possible to keep either version of the file.
open the conflicting file in sublime and look for "<<<<", "====" and ">>>>". These indicate the parts of the file that are conflicted. This can then be manually edited and saved. The merge can be completed by committing the updated files.
If a file (e.g. index.html) is conflicting you can find keep either your own (--ours) or the version you pulled in (--theirs) with the following commands.
git checkout --ours index.html
git checkout --theirs index.html
- git log -> lists all the hashes of previous commits
- git checkout 'hash' -> checkout out that specific hash
git submodule foreach git pull origin PycQEDbranch
Create a branch at the detached head state
git branch temp
git checkout temp
git merge branchname
Ignoring files computer-specific It is possible to ignore changes made to a file without having to add an entry to .gitignore. An example where this might be useful is with config files, where the path to directories may vary per computer. To do so enter the following command into your git shell: git update-index --assume-unchanged 'filename'