- get your repositiory
- checkout and create your local branch
- initialize submodules
- update submodules, download the code
- add files to git
- commit file(s)
- push your changes to remote branch
- merge develop branch into your private branch
- resolve conflict
- named stash
- see all commits on particular file
- to see all the branches
- To unstage the files staged for commit
- list files to be pushed
- rename local branch
- undo a local commit
- merge one branch into another
- create a new branch
- delete a branch
- submodules init/update
- compare versions of same file from two different branches
- change default editor for commit message to vim
- if you encounter "fatal: unable to access 'https:URL': Peer's Certificate issuer is not recognized"
- get all files that have been modified in branch
- determine URL from where local repo was cloned from
- change message of pushed commit
- merge an upstream repository into your fork
git clone <your repository url>
cd <your project directory>
git checkout -b local-branch origin/develop
git submodule init
git submodule update
git add <path to file>
git commit <path to file(s)>
e.g. git commit example.php gui/anotherfile.php
git push origin local-branch:remote-branch
git pull --rebase
git merge origin/develop
git push origin local-branch:remote-branch
git mergetool path/to/file
git stash save "WIP on X"
git stash list
This would output something like this: stash@{n} ... "WIP on X" stash@{m} ... "some other message" stash@{l} ... "some other name"
git stash apply stash@{n}
git diff stash@{n}
git log path/to/file
git branch
Git will put a * before name of the branch you are currently on.
git branch -r
git remote show origin
or
git -vv
If you execute only this:
git reset --hard
It would unstage all files staged for commit.
A this point, file(s) would remain in staged for commit. To unstage them, refer point 13.
git checkout <destination branch>
git merge <source branch>
All new commits from source branch should be available on destination branch, so just push to your remote destination branch.
Create branch on your local machine: `git branch `Push this branch to remote: git push origin <new branch name>
Switch to your new branch: git checkout <new branch name>
Add new remote to your branch: git remote add <name of remote> <url>
Delete her remote tracking branch: git push origin :<branch name>
Update submodules: git submodule update <submodule name>
In some cases you may face conflicts while updating submodules, and because of them the update gets aborted. In such a case, use --force option:
git submodule update <submodule name> --force
git diff <branch 1> <branch 2> -- <relative path to file>
git config --global core.editor vim
Make sure you have valid id_rsa and id_rsa.pub files in your .ssh folder.
export GIT_SSL_NO_VERIFY=true
git diff --name-only <branch in question> $(git merge-base <branch in question> <branch where you would merge back this branch>)
If your shell does not understand $(), you can use back-ticks instead.
git config --get remote.origin.url
git rebase -i <commit you wish to change>^
This will open some editor for you (e.g. vim), which will have list of commit(s) along with actions for them. Default action is pick.
Replace pick by reword. Then save it (e.g. :wq in vim).
For each commit you are going to change, it will open another editor window with current commit message. Change it the way you want and save+quit.
Finally, forcibly push all those changes. git push origin --force.
git checkout <branch you wish to merge to>
git pull https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git <branch you wish to merge>
Resolve merge conflicts, if any.
git push origin <branch you wish to merge to>
Added point # 22. change default editor for commit message to vim.
I just installed ubuntu 15.04, and used git to work with my code. When I went ahead to commit my code change and add commit message, git opened nano editor instead of vim. A quick googling gave me this tip.