More git Commands here: www.siteground.com/tutorials/git/commands.htm
Git commands that can save your life: http://manojbits.wordpress.com/2013/10/18/git-commands-that-can-save-your-life/
http://gerrit-training.scmforge.com/git-gerrit-workshop.html#git-info
- git init # initializes the git repository
- git add <filename> # add files git repository
- git commit -m "message here what you did or what you added"
- git remote show origin # shows remote branches
- git config --get remote.origin.url # will show remote repo url
- git status # displays the status of what you did in past with the repository with dates and message you typed in while making a commit
- git branch <name of the branch here> # this will create a branch of the master you can work on , at office I am supposed to work on my branch not permitted to master.
- git log --oneline --pretty=format:"%H" will output all the commit SHA ID
- git rev-parse origin/master # will output latest commit id of remote/origin, provided you run git fetch before.
- git config --get remote.origin.url # will output the repository remote URL
- git ls-remote {url} refs/heads/{branch} | awk '{print $1}' # will output the latest commit SHA ID of the given branch
- git rev-parse master # will output latest commit ID locally
- git checkout master # this will checkout if you are in branch to master, or if you are in master then you type this
- git pull origin <branchName> # pulls updated code from github or remote
- git checkout mybranch # so now I will checkout from mybranch to master
- for what I learnt at home, since I use github.com, here is how I will put the files to github using ssh but before that few things to do.
- git remote set-url pySan https://github.com/<username here>/pySan.git
sets url for remote repository
- git remote prune origin
Deleting the refs to the branches that don't exist on the remote clean local repositories
- git remote -v # to list url already set on local repository
- git remote set-url origin https://[email protected]/sanfx/pySan.git
# this will set url for my github repository to put code on github.com
- git push origin :<branchName>
# will delete the git branch from remote - git pull origin <branchName> # to pull specific branch from remote
- git push -f origin <branch name> # any branch name you specified that you want to put to server on github.com or <branch name> could be master if you are going to put update the master .
- git push -u origin <newBranchName> # this creates a remote branch if it doesn't exist)
- git diff branchNameCompareTo branchName -- file_to_diff.ext
# to compare files from two different branches and this one i learnt today from stackoverflow - git for-each-ref --sort=-committerdate refs/heads/ --format='%(committerdate:short) %(authorname) %(refname:short)' # this will list all the local branch in a sorted order and jusified
- git for-each-ref --sort=-committerdate refs/heads/ # will print the commit ssh keys
- git ls-remote --heads origin # this will list all the remote branch commits
- git branch -m <oldBranchName> <newBranchName> # rename a git branch
- git pull
then to get the branch - git checkout -b <branchName> origin/<branchName>
<branchName> is the one that is pushed and you are trying to pull it on different location - git push all <branchName>
to push to multiple repositories - git rerere -- The git rerere functionality is a bit of a hidden feature. The name stands for "reuse recorded resolution" and as the name implies, it allows you to ask Git to remember how you've resolved a hunk conflict so that the next time it sees the same conflict, Git can automatically resolve it for you. To enable the rerere functionality, you simply have to run this config setting:
- $ git config --global rerere.enabled true
- git reset --hard HEAD~1
undo last merge/ commit