Skip to content

Instantly share code, notes, and snippets.

@ebot
Last active May 12, 2017 17:30
Show Gist options
  • Save ebot/305849 to your computer and use it in GitHub Desktop.
Save ebot/305849 to your computer and use it in GitHub Desktop.
git cheat_sheet

Working with Remote Branches Locally

Setting up your project to be shared

Replace proj with the location of your project directory.

  1. git clone --bare ~/proj proj.git
  2. touch proj.git/git-daemon-export-ok

Creating a remote branch

  1. Create the remote branch:
    git push origin origin:refs/heads/new_feature_name
  2. Make sure everything is up-to-date:
    git fetch origin
  3. Then you can see that the branch is created:
    git branch -r
  4. Start tracking the new branch:
    git checkout --track -b new_feature_name origin/new_feature_name
  5. Make sure everything is up-to-date:
    git pull
  6. After meging back to master, delete the remote branch:
    git push origin :heads/new_feature_name

Use the Branch from Another Location

When you get to another computer or clone the git repository to a new computer, then you just need to start tracking the new branch again.

  1. git branch -r to show all the remote branches
  2. start tracking the remote branch locally
    git checkout --track -b new_local_branch_name_ origin/remote_branch_name

Reference

Creating and applying patches

Create the patch

  1. Create a patch for the entire branch against master
    git format-patch master --stdout > name_of_your.patch
  2. Create a patch for the last x commits
    git format-patch -x

Applying a patch

  1. Find out the statistics on this patch that you will be applying:
    git apply --stat name_of_your.patch
  2. Test the patch to make sure there are no errors:
    git apply --check name_of_your.patch
  3. With no errors, you can sign off and apply the patch:
    git am --signoff < name_of_your.patch

Reference

  1. Ariejan
  2. git format-patch
  3. git apply
  4. git am

Setting up your project to be shared

  1. Clone your project to a bare version
    git clone --bare ~/proj proj.git
  2. Set the daemon export flag
    touch proj.git/git-daemon-export-ok

Tagging

  • Tag and sign latest update
    git tag -s -m "message about tag or release." tag_name
  • List tags
    git tag -l -n1
  • Verify the signature
    git tag -v tag_name
  • Pushing tags to remote repo
    git push origin —tags
  • Deleting tags
    • Local
      git tag -d tag_name
    • Remote
      git push origin :refs/tags/tag_name

Navigate Between Tags

  • Checkout a specific tag for troubleshooting
    git reset --hard tag_name_here
  • Return to the latest code from a tag"
    git reset --hard origin/master

Reference

Command Description
:Glog history
:Glog -- % history for current file
:copen open history navifation pane

Add the following so that you do not have to enter your username when interacting with the specified URL:

[credential "https://github.com"]
  username = (MyUsername)

To have git remember your password, follow these instructions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment