Skip to content

Instantly share code, notes, and snippets.

@saurabh-sp-tripathi
Last active May 22, 2020 17:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saurabh-sp-tripathi/115f549ac3d97cea5844f1d44756871b to your computer and use it in GitHub Desktop.
Save saurabh-sp-tripathi/115f549ac3d97cea5844f1d44756871b to your computer and use it in GitHub Desktop.
This gist contains list of reference of git commands or workflows
  • list branches (local i.e tracking and remote): git branch -vv
  • checkout: git checkout --track origin/abranch
  • Create remote branch
    //Create a new branch:
    git checkout -b feature_branch_name
    //Edit, add and commit your files. Push your branch to the remote repository:
    git push -u origin feature_branch_name

rename local branch : > git branch -m <new-name>

  • delete remote branch $ git push --delete <remote_name> <branch_name>

  • delete local branch $ git branch -d <branch_name>

  • Remote branches deleted but still shows in git branch -r to clean up : git remote prune origin

  • Unstage i.e undo commit : git reset HEAD~

  • make 2 branch identical (a -> b)

######### better way ##############
### ------ to make downstream same as upstream
    git checkout -b tmp origin/upstream
    git merge -s ours downstream         # ignoring all changes from downstream
    git checkout downstream
    git merge tmp                        # fast-forward to tmp HEAD
    git branch -D tmp                    # deleting tmp
######### better way ##############
######### Deprecated ##############
    git checkout b
    git reset --hard a
    git pull 
    git push
######### Deprecated ##############    
  • Revert back to a specific commit:
        > git revert --no-commit z7kwdn4t1s..HEAD 
        > git add . 
        > git commit –m  “commit message” 
        > git push 
  • Revert back specit file
    git checkout -- <filename>
  • List logs from local branch
>git log --graph --abbrev-commit --decorate --first-parent develop
> git checkout <branch-name>
> git branch branchname <sha1-of-commit>
## better way
> git branch branchname HEAD~3
## or
> git checkout -b branchname <sha1-of-commit or HEAD~3>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment