git tips

git tips

How to create git repository on server

$ git init -bare —shared test.git
$ git update-server-info

Create tag

# Annotated Tags
$ git tag -a v1.4 -m 'my version 1.4'

# Lightweight Tags
$ git tag v1.4-lw

Sharing Tags

git push origin --tags

Check out Tags

$ git checkout -b version2 v2.0.0 http://git-scm.com/book/en/v2/Git-Basics-Tagging

Push tag

git push origin rel-1.4
git push origin --tags ( push all tags)

Delete tag

#delete local tag first
git tag -d rel-1.4 

git push origin :refs/tags/rel-1.4
git push origin --delete rel-1.4

Push remote branches

git push origin newfeature

Delete remote branches

git push origin :newfeature

Delete local branches

git branch -d newfeature

How to merge code locally

  1. Fetch and check out the branch for this merge request
git fetch git@gitlab.com:seawaywen/ttllaw_site_django.git feature-integrate-deploy-manager
git checkout -b seawaywen/ttllaw_site_django-feature-integrate-deploy-manager FETCH_HEAD
  1. Review the changes locally

  2. Merge the branch and fix any conflicts that come up

git fetch origin
git checkout origin/master
git merge --no-ff seawaywen/ttllaw_site_django-feature-integrate-deploy-manager
  1. Push the result of the merge to GitLab
git push origin master

Reset to a revision

git reset --hard cedc856
git push --force origin master

Undo last git commit

git reset --soft HEAD~1

or

git reset --soft HEAD^

Note the --soft flag: this makes sure that the changes in undone revisions are preserved. After running the command, you'll find the changes as uncommitted local modifications in your working copy.

git reset HEAD^

when you want to undo the latest commit include everything you'd staged

If you don't want to keep these changes, simply use the --hard flag. Be sure to only do this when you're sure you don't need these changes anymore.

git reset --hard HEAD^

NOTE:
HEAD refers to the current commit(the tip of the currently checked-out branch)
HEAD^ is the commit before the current one

create a git path

git format-patch -1 <sha>

apply a git path

git am < patch.file