These are my personal notes on GIT.

Basic Commands


Command

Description

git clone <repository_url>Clone a repository

git clone <repository_url> <folder>

Clone a reposiory into a folder
git statusDisplay 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 pushPush 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 showGet 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 branchList local branches
git branch -rList 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 -iAdd 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 --hardReset all of your changes to your local branch.

git reset HEAD~1

Revert the commit.

git clean -fRemove 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 listList 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.


  • No labels