We, in the company, have decided we want to start small regular education program where we can share best practices, new interesting technologies or whatever interesting we have seen and might be beneficial to others. We make up to one hour long session together where we present and discuss one selected topic. This blog is just short summary for future generations 🙂 First part is dedicated to Git.
When you work in a team, you need to incorporate changes from others with your work. The default behaviour for
git pull is that others’ changes are merged with your local commits. This leads to non-linear history and lots of “merge” commits.
Other alternative is
git pull --rebase where source is updated to latest changes and your local work is “replayed” over the new code base. Only drawback is that in case of conflicts your original commit (based on the old code base) is lost and you can’t check your raw changes.
For more detailed discussion check this tutorial that also discuss other useful concept – feature branches.
Sometimes you don’t want to commit your current work but you want put them away for a while. E.g. you need to make urgent hotfix or you want to pull without commit. It can be easily done –
git stash and when you want your changes back just call
git stash pop. You can stash more work, check what do you have in stash etc. For more details check more stash commands.
You can “download” server changes without affecting your work (as via git pull):
git fetch. The “problem” is that you don’t see them in standard
git log output. It can be easily solved:
git log --all and similarly
But git log is not so nice be default. It has lot of configuration options but to write it all the time is not the way. Luckily you can define your git aliases, e.g. alias for
lg defined as
log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit