2/7/2011 - 7:23 PM

useful git commands

useful git commands

#push a local branch to repo if does not exist remotely
git push origin branch_name:refs/heads/branch_name

# to start tracking a branch
git branch --track branch_name origin/branch_name

# create remote git branch from head of master
git push origin origin:refs/heads/branch_name

# create a remote branch from another branch's head
git push origin existing_branch_name:new_branch_name

# checkout a remote tracking branch
git checkout -b branch_name origin/branch_name

# manually make the local non tracking branch to track the remote branch
git config branch.branch_name.remote origin
git config branch.branch_name.merge rename_task

# delete a remote branch
git branch -d -r origin/branch_name
git push origin :branch_name

# to only push the current branch to the remote repository
git push origin branch_name OR
git push origin HEAD

# to keep history clean
git commit -m "commit message"
git fetch
run tests
if everything is fine
 git push origin branch_name
 git rebase origin/branch_name
 git push origin branch_name

# to commit a patch
git add -i
then select the option by typing p
and follow the rest

# to amend
git commit --amend

# Useful Git alias, found somewhere on the Internet
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative