I have been using git for quite some time now and thought of sharing some advanced git commands that you may find useful whether you are working in a team environment or on your personal project.
1. Export changes done in last commit
This command i have been using regularly for sending the changes done to another person for review/integration who is not on git. It will export the recent committed changed files to a zip file.
git archive -o ../updated.zip HEAD $(git diff --name-only HEAD^)
2. Export changed files between two commits
Similarly if you need to export changed files between two commits, you can use this one.
If you wish to clone only specific branch from a remote repository without having to clone whole of the repository branches, this will be useful to you.
5. Check if your Branch changes are part of Other branch
cherrycommand lets you check whether your branch’s changes are present in some other branch or not. It will display the changes on current branch to given branch and indicate with a + or – sign to indicate if that commit is merged or not. + indicated not present while – indicates present in the given branch. Here is how to do that:
git cherry -v OTHER_BRANCH_NAME_HERE
#For example: to check with master branch
git cherry -v master
Sometimes you need to start a new branch and do no want to carry the long history along, for example, you want to place the code in public domain(open source) but do no want to share the history.
git checkout --orphan NEW_BRANCH_NAME_HERE
7. Checkout File from Other Branch without Switching Branches
Here is how to fetch just that file you need from other branch without even have to switch branches.
If you are working in a team and all of them are working on same branch, chances are you are going to use fetch/merge quite often. but this sometimes resets your environment specific config files which you have to change every time after merge. Using this command, you can ask git to ignore the changes to specific file. So next time you do merge, this file won’t be changed on your system.
9. Check if committed changes are part of a release
The name-rev command can tell you the position of a committ with respect to a last release. Using this you can check if your changes were part of the release or not.
If you are working in a team which is working on same branch, then you have to do fetch/merge or pull quite often. Branch merges in git are recorded with merge commit to indicate when a feature branch was merged with mainstream. But in the scenario of multiple team members working on same branch, the regular merge causes multiple merge messages in the log causing confusion. So you can use rebase with pull to keep the history clear of useless merge messages.
git pull --rebase
Also, you can configure a particular branche to always rebasing: