None

dev notes

Git Commands

04 Jan 2013

Tag: git

folked repo sync with remote orig repo

git remote add upstream https://xxxx.git
git fetch upstream
git merge upstream/master

checkout remote branch

To fetch a branch, you simply need to: shell git fetch origin This will fetch all of the remote branches for you. You can see the branches available for checkout with: shell git branch -v -a

With the remote branches in hand, you now need to check out the branch you are interested in, giving you a local working copy: shell git checkout -b test origin/test

tag:

create git tag TAG_NAME
delete git tag -D ..
push to remote git push --tags

delete branch:

$ git branch -D bugfix
git push origin :<branchName>
Or:
git push origin --delete <branchName>

rename branch:

git branch -m <oldname> <newname>

If you want to rename the current branch, you can simply do: shell git branch -m <newname> git rebase --abort && git pull

delete committed changes:

Careful: git reset –hard WILL DELETE YOUR WORKING DIRECTORY CHANGES Assuming you are sitting on that commit, then this command will wack it… shell git reset --hard HEAD~1

The HEAD~1 means the commit before head. Or, you could look at the output of git log, find the commit id of the commit you want to back up to, and then do this: shell git reset --hard <sha1-commit-id>

If you already pushed it, you will need to do a force push to get rid of it… shell git push origin HEAD --force

using rebase shell git rebase --onto <branch name>~<first commit number to remove> <branch name>~<first commit to be kept> <branch name>

EG:

number Hash Commit Message Author
1 2c6a45b (HEAD) Adding public method to access protected method Tom
2 ae45fab Updates to database interface Contractor 1
3 77b9b82 Improving database interface Contractor 2
4 3c9093c Merged develop branch into master Tom
5 b3d92c5 Adding new Event CMS Module Paul Tom
6 7feddbb Adding CMS class and files Tom
7 a809379 Adding project to Git Tom

to remove commit 2 & 3 above: shell git rebase --onto repair~3 repair~1 repair

revert local commit:

git reset --hard remotes/origin/HEAD

Reference:

comments powered by Disqus