Git Frequently Used Commands

Git is a Version Control System software used to keep track of changes in computer code bases, including configuration files. I have found the following commands useful.

Making git “forget” about a file that was tracked but is now in .gitignore:

git update-index --assume-unchanged <file>

Set local branch to track remote branch:

git branch [local branch] --set-upstream-to [remote]/[branch]

Rename a Branch (local and remote)

git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push to track the new remote

Delete last commit (local and remote)

git reset --hard <sha1-commit-id>
git push origin HEAD --force # For remote delete

Push new branch and follow

git push -u origin new_branch

Push/Pull a local/remote branch to remote/local repo

git [push|pull] [to|from repo] :[local|remote branch]

Push/Pull all branches

 git [push|pull] –-all [remote|local]

Delete a branch, local or remote:

 git branch -d [branch]


 # delete local first
 git push origin :[branch]

Force git to overwrite local files on pull

 git fetch --all
 git reset --hard origin/master

Tell Git to Ignore File Attributes
This is useful when moving from a Unix environment to a Windows environment. In this case, files that have not been edited will show up as different because the filemode has change.

git config core.fileMode false

Leave a Reply

Your email address will not be published. Required fields are marked *