These are my personal notes on GIT.
Basic Commands
Command | Description |
---|---|
git clone <repository_url> | Clone a repository |
git status | Display the status of your current branch. |
git add <file> | Add a file to the change list. |
git diff <file> | See changes to a file |
git commit -m "message" | Commit files in your change list. |
git push | Push your commit to the server (origin) |
git push -u origin <BRANCH> | Push local branch to server |
git pull --rebase | Pull changes from the server and move your changes on top. It is a good practice to rebase your changes so as to minimize merges. |
git checkout <branch> | Switch to a branch |
git log git log -2 git log --pretty=oneline git log --pretty=format:'%h %<(20)%an %s | Show history of current branch Show history (limited to the last 2 entries) Show history (One entry per line) Column formated output |
git remote -v show | Get git URL from source folder. |
Branching Commands
Command | Description |
---|---|
git checkout -b <branch name> | Create a branch from your local |
git push origin <branch_name> | Push branch to server (origin) |
git branch | List local branches |
git branch -r | List remote branches |
git branch -d <local branch> git push origin :<local branch> | Delete a branch and push to server(origin). |
git fetch origin git pull origin develop | Merge develop into current branch |
git checkout <other_branch> git pull git checkout <your branch> git merge <other_branch> git commit git push | Merge another branch into yours |
git checkout <branch_to_rename> git checkout -b <new_branch_name> | Rename a branch This command will create a new branch from your current branch. |
git add -i | Add files to git interactively |
Advance Commands
Command | Description |
---|---|
git reset <file> | Un-stage a file Remove a file from add list |
git checkout <file> | Revert changes to a file |
git reset --hard | Reset all of your changes to your local branch. |
git reset HEAD~1 | Revert the commit. |
git clean -f | Remove files not under version control. |
git checkout HEAD <file> | Replace file from HEAD. Use to undelete and reset a deleted file. |
git config --get remote.origin.url | Get URL of current Git repository. |
git remote show origin | Show Git repository information |
git reset --hard <GITREF> git push -f | Revert the current branch to the specified gitref. (Rewinding). The push forced may be required to push this to origin. DO NOT DO THIS! |
git fetch origin git rebase -i origin/develop > delete commits that are not yours write and exit | Fixup branch |
Stash Commands
Command | Description |
---|---|
git stash git stash save <stash_name> | Stash your changes for later |
git stash pop [ DON'T USE, USE APPLY ] | Apply your stashed changes and remove from stash. |
git stash list | List all stashes |
git stash apply <stash> | Apply specific stashed changes to your local. |
git stash branch <branch name> | Create a branch from the stash |
Tagging
Command | Description |
---|---|
git tag <tag> | Create tag ex: git tag v0.2.0 |
git push origin --tags | Push tag to origin |
Git Documentation
See Git Reference for more info.