Skip to content

Instantly share code, notes, and snippets.

@sagarpanda
Last active November 8, 2019 04:01
Show Gist options
  • Select an option

  • Save sagarpanda/5404146 to your computer and use it in GitHub Desktop.

Select an option

Save sagarpanda/5404146 to your computer and use it in GitHub Desktop.
git common commands
git clone [email protected]
git remote add origin [email protected]
git pull
git remote -v
git push origin master
# create patch file for last 3 commits
git format-patch HEAD~3..HEAD
#add new-file and modified file onto stage
git add <file_path>
git commit -m "message"
#commit all modified files
git commit -am "message"
#add deleted and modified files to the staging
git add -u
#to unstage the file
git reset HEAD -- <file_path>
# go back to last commit without removing currently committed files --soft
git reset HEAD~1
git reset HEAD^
# come back to current commit
git commit -a -c ORIG_HEAD
git reset HEAD@{1}
#revert the modified files and also can get locally deleted files
git checkout HEAD <file or folder path>
git checkout .
git status
git status -s
git branch <branch_name>
git checkout <branch_name>
#create and switch to the branch
git checkout -b <branch_name>
#Push the branch on github
git push origin <branch_name>
#lists all branches with latest commits
git branch -v
#list all remort branch
git branch -r
#To delete a local branch
git branch -d <branch_name>
#To remove a remote branch
git push origin :<branch_name>
#Merging branch to master
git checkout master
git merge <branch_name>
#To undo a merge that was NOT pushed:
git reset --merge ORIG_HEAD
#If during the merge you get a conflict, the best way to undo the merge is:
git merge --abort
#Rebase last 2 commit with 1st commit
git rebase -i HEAD~2
#Abort rebase
git rebase --abort
#Conflict resolve by HEAD change while merging branch into master (git checkout master; git merge mybranch)
grep -lr '<<<<<<< HEAD' . | xargs git checkout --ours
#Conflict resolve by Branch change
grep -lr '<<<<<<< HEAD' . | xargs git checkout --theirs
#fetching a remote
$ git pull remotename branchname # Grabs online updates and merges them with your local work
https://help.github.com/articles/fetching-a-remote/
ref
http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment