Working with git¶
|Git Commands||What it does|
|git clone <repo>||Used to clone the repo
|git commit||Commit an applied change on the given branch|
|git remote||Track a remote branch|
||Revert changes in a commit|
||The git fetch command imports commits or tags from a remote repository into your local repo.|
Updates your repo. Shorthand for
Recommended to use it with –rebase.
Lists commits made in the current branch of the repo. Check this.
Issues with Pull Requests¶
Helpful tips for new contributors¶
Get into OpenHatch workflow .
- Understand your problem first.
Learn to go to a certain commit.
- Tip: Each commit has a hash value(SHA-1) which is fixed. Switch to a commit.
- If you need to modify a single commit as requested by the maintainer in the pull request revert the old commit with a new commit and push it mentioning the changes you have made:
- Note: Commits do not technically change when we force push the commit, reset or modify them. But the hash gets updated, and the new hashed commit gets tagged to that branch. You can easily find you previous commit(s) on github too just by adding
/commit/<branch>to the repo address. It will show you the remote git log. See the hash get changed after rewriting the commit.
- Sometimes you have two or more commits on your pull request, which is usually not desired by maintainers. The solution is to do an interactive rebase and squash the previous N commits:
- Tip: Please understand interactive rebase. Checkout the branch the pull request represents, count the number[N] of commits you need to squash from the pull requests or
git logon that branch, then
git rebase -i HEAD~N. N (number of commits before) is usually 2 if you want to squash 2 commits. Change pick to squash for all but one line. Save the configuration. Then force push the new commit
git push -f origin <branch>.
- If you have unwanted commits attached to the pull request or history is broken then you need to do an interactive rebase :
- Tip: It is better to tell others that you are having such problem as it needs rewriting history. Please understand rebasing and please see your logs. The solution is an interactive rebase Command:
git rebase -i HEAD~N(N gives the number of the revisions up in that branch). Try to pick N carefully count the commits as maintainers will ask you to give the finalized result in a single commit.
- The interactive rebase on that branch will show the commands that runs on that branch and finally shows on the pull request. Delete the commits you don’t need and keep the ones you need. Squash the needed commits to a single commit.
- Note: Branches are technically a tagging system to commits that have a hash value, they are relative, even the master branch. It can operate with commands like squash, pick and many others. The commands are played from top to bottom on each commit and finally shown in the pull request. See the options.
Resolving Merge Conflicts¶
Note: The merge conflicts can also be resolved with an interactive rebase.
Tips on Installing kdiff3¶
$ sudo apt-get install kdiff3
$ brew install kdiff3
Recent Git versions have built-in support for kdiff3.
$ git config --global merge.tool kdiff3
git mergetool launch kdiff3.
Become a git Expert¶
.zshrcor any file you want to source. Open
.bashrcon your favorite text editor. Follow the instructions.
alias gc="git commit -m "$1"" alias shortform="the longer version of the command"