Skip to content

Instantly share code, notes, and snippets.

@skuppa
Last active August 29, 2015 13:56
Show Gist options
  • Save skuppa/8909493 to your computer and use it in GitHub Desktop.
Save skuppa/8909493 to your computer and use it in GitHub Desktop.
Git Tips

Remove staged file after updating the .gitignore

$ echo 'out/' >> .gitignore
$ git rm -r --cached out/

Shelve Changes using Branch

If file is not committed locally

$ git reset HEAD
$ git create branch newfeature
$ git checkout newfeature
$ git add -A .
$ git commit -m "shelving partially working copy for new feature"
$ git checkout master

If file is committed locally

git branch newfeature

// reset to previous commit
git reset --hard HEAD^ 

Getting remote branch

  • Get all remote branches
git branch -a
* master
  remotes/origin/HEAD
  remotes/origin/master
  remotes/origin/experimental
  • To checkout the changes
git checkout origin/experimental
  • To track the changes, you need to create a local branch
git branch -b experimental origin/experimental
  • Now you can look both branches
git branch
*experimental
 master

Remove untracked files

  • To remove untracked files
git clean 
git clean -f // clean.requireForce is not set to false, default is true
  • To clean directory (do after removing the file)
git clean -d -f
  • To clean the files from .gitignore
git clean -X -f

Getting upstream branch as local branch

git upstream pull
git checkout -b newbranch upstream/master

Reference: http://stackoverflow.com/questions/4410091/github-import-upstream-branch-into-fork

Pushing local branch to remote

git push -u origin mynewfeature

Creating branch from tag

git checkout -b <newbranch> <tagname>

# example
git checkout -b hotfix-v2 tag-v2

push local release branch to remote master

push -v --tags --set-upstream production release-ver-0.3.002:master

Tag

Creating tag

git tag -a <tag-name> -m <message>'

# example
git tag -a v1.2 -m 'version 1.2'

Pushing a tag to remote

git push <remote-name> <tag-name>

# example
git push origin v1.2

Updating a tag

git tag --force v1.2

# example
git tag --force v1.2

Pushing updated a tag

git push --force <remote-name> <tag-name>

# example
git push --force origin v1.2

Allowing empty commit for heroku

git commit --allow-empty -m "empty commit"
git push heroku master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment