-
Notifications
You must be signed in to change notification settings - Fork 47
HowToGit
We manage our development through issues tracking in Scipion GitHub project.
A nicer view of the Scipion issues is provided by Waffle.io
-
General
-
Git Book: Read chapters 2 and 3
-
Specific
git config --global user.name "Your Name" git config --global user.email "your@email.domain"
git config --global alias.co checkout git config --global alias.br branch git config --global alias.ci commit git config --global alias.st status
Some others handful aliases for using the git-flow methodology.
# To create a new feature branch and publish to origin git config --global alias.new-feature '!git checkout -b $1 master \ && git push -u origin $1 #' # To create a hotfix branch (now from v1.0) git config --global alias.new-hotfix '!git checkout -b $1 v1.0 \ && git push -u origin $1 #'
List all branches:
git branch -a
Create a new branch and move to it:
git checkout -b NEW_BRANCH
Then you can publish it to origin:
git push -u origin NEW_BRANCH
Locally delete a branch
git branch -d OLD_BRANCH
This must be done in a different branch than OLD_BRANCH
The previous command does not allow to locally remove unless the OLD_BRANCH has been merged to another branch. If you want, anyway to locally remove the branch do
git branch -D oldBranch
To delete the branch remotely (after delete it locally):
git push origin :OLD_BRANCH
Everybody else has to "update" the list of branches in the origin, so that they also get it deleted:
git remote prune origin
To create a local branch at the status of a remote branch:
git pull git checkout -b newlocalbranchname origin/remotebranchname
To create a branch and also set to track the remote branch:
git pull git checkout -t origin/branch-name [-b newlocalbranch]
git checkout -b newBranchWithBugFix git commit -m "Your comment" yourFiles git push -u origin newBranchWithBugFix
To see differences between branch A and B:
git diff --name-status A..B
To see differences in a particular file between branch A and B:
git diff A B myFile
git diff origin/branch --name-only
Let’s say that there is a file in branch2 with some differences with respect to branch 1. Then you want to take these differences and put them in branch 1. From branch 1, you must do
git diff branch1..branch2 yourFile > patchFile git apply patchFile
If you run the git diff without file, then all changes between the two branches are dumped into the patchFile.
To create a tag:
git tag -a TAG_NAME -m "TAG MESSAGE"
You can submit to a shared server in the same way as a branch:
git push origin TAG_NAME
To delete a tag:
git tag -d TAG_NAME git push origin :TAG_NAME
Often, when you’ve been working on a part of your project, things end in a messy state. You want to switch branches for a while in order to work on something else. The problem is, you don’t want to do a commit of half-done work (just to be able to get back to this point later). The answer to this issue is the git stash command:
$ git stash
Now you can easily switch branches and do work elsewhere: your changes are stored on your stack. To see which stashes you’ve stored, you can use:
git stash list:
You can reapply the one you just stashed by using the command shown in the help output of the original stash command:
git stash pop
Let’s say you are in the middle of a merging, and you regret from the changes you have already been introducing. Files that are not related to the merging conflicts are unaffected by this command.
git merge --abort
If you want to avoid merge commits follow this link
In summary use:
git pull --rebase
or make it the default behavior in the config.
In case of looking for a commit by date, the repository can be moved by:
git co `git rev-list -n 1 --before="2011-06-21 13:37" master`
git log origin/master..master
[[Undo a commit]] == Revert the changes introduced by a commit
If you have committed and pushed some changes, you may undo them by
git revert [commitHash]
git grep
-
Look for specified patterns in the tracked files in the work tree.
git blame
-
Show what revision and author last modified each line of a file.
Since January-2016, we started to follow the git-flow development methodology using git.
Summarizing, there are two main branches: master and devel. New branches should be opened from devel for each new feature that will be included in the next release. Feature-branches should be merged back through Pull Requests in GitHub to allow peer-review and discussions. Master branch should always contain a released status. When we are ready for a new release, we should create a release-branch from devel and only commit bug-fixes to it. When this release-branch is merged (also through Pull Request) to master, it means a new release that should be tagged in master.
The following image illustrates very well this workflow and a very nice explanation can be found here.
This is a tentative approach about how to set up you git using scipion. Currently, there is one repo and all developers are mainly creating branches over 70 now making it, at least confusing.
Look for the fork icon (top-right) and make a Fork on your account o institutional account. image::https://help.github.com/assets/images/help/repository/fork_button.jpg[Fork icon]
git clone git@github.com:YourUserNameHere/scipion.git --origin privatescipion This should bring your repo to your machine with the remote name "privatescipion". Feel free to use a different name. It’s yours!
You can keep them, but to avoid confusions, you might want to start with a branchless repo. Well, I guess you need to keep one: Keep master.
git remote add I2PC https://github.com/I2PC/scipion.git This adds a second remote name I2PC. Again feel free to name it your way.
Now, when you need a branch to work on something new, that branch should go to your "privatescipion" but start from, usually, I2PC/devel. git checkout -b mynewfeature devel now you can work locally as usual with your commits, etc.
Whenever you want to send changes, you must send them to your remote: git push --set-upstream privatescipion mynewfeature
Let’s update your "mynewfeature" branch with possible devel changes.
git checkout devel git pull git checkout - git merge devel
Resolve conflicts if any. And push the branch again to your privatescipion with: git push
Finally, just create a PR across forks using as base I2PC/devel