So here is my *very* happy path sample workflow, using local branches, with explanations for first time users of Git. See here for a worksheet with useful git commands and their uses and a sample workflow. This covers only what this post covers.
You will aslo see references here to “git tf”. This is not an alias but a cross-platform, command line tools that facilitate sharing of changes between TFS and Git. The commands are the same as the regular Git ones. But slightly different for pushing and pulling. See here for more information.
A familiar workflow:
- Get the latest code
- Create somewhere to put the changes you are about to make
- Make changes
- Make sure you are happy with them and want to integrate them back into the main repo.
- Check for any more updates
- Push your code into the remote repo
Now broken down into the Git steps to achieve the above.
1. Get the latest code
Make sure you are on master. Use git status
to check.
Pull down the latest changes onto master git pull
2. Create a new branch for your story work.
Name it after your story so you can remember it later. git checkout -b [branchname]
If you do a git status
now you will see you are on your new branch.
3. This is where you code as normal, running your tests etc.
4.Commit your changes to your branch.
When you are a point where you are happy with your changes and you want to pull in everyone else’s changes… You can commit as many times as you like to one branch but try to keep them small and in a working state.
A git status
will show you your changes.
You will see the files that git is tracking and has staged and those that it has not. git add .
Or git add -A
will add any untracked files.
Next commit your files to your branch. git commit -am "[message]"
When you do a git status
now, you should see no changes.
If you do a git log
you will see that your commit is now part of the branches history.
5. Get latest code on master
Move back onto your master branch git checkout master
If you do a git log
at this point, you will notice that your commit is not yet on master, and the latest commit will be from when you last pulled.
git pull
will bring down any more changes.
6. Update your branch with lastet code
Move back to your story branch git checkout storyname
Next you are going to rebase your branch. When you originally created your branch it was based on point in time x, since there have been additional changes (time y), you want to tell your branch that you actually want it to be based from time y and you want your changes on top of that. So now git rebase master
will update your branch with all the changes that are now in your master branch. As you watch the output you will see that git pulls out your change, fast forwards to time y and then replays your change on the top. Now you may have conflicts at this point if two people have changed the same thing but will assume things are all good.
Now run your tests and make sure everything is good.
7. Get your changes back into the main repo.
Move back to your master branch git checkout master
Merge your branch back into master with git merge storybranch
git push
will then send up changes to the remote repository.
Next time… Merge conflicts…..