Skip to content

Instantly share code, notes, and snippets.

@ZenabKhan
Last active January 28, 2017 09:58
Show Gist options
  • Save ZenabKhan/a7e277702eb22d391d23d9a1321ca083 to your computer and use it in GitHub Desktop.
Save ZenabKhan/a7e277702eb22d391d23d9a1321ca083 to your computer and use it in GitHub Desktop.

Useful Git Commands

Make git repository

//You ned to go inside the project folder
git init

Clone repo

git clone <repo link>

Setting Git configs

git config --global user.name <name>
git config --global user.email <email>

Check repo status

git status

Display commit history

git log

Stage a file for commit

git add <file>

Stage all changes for commit

git add -p

Commit the staged changes

git commit -m "<message>"

Push changes to remote

git push

Get all changes from from

git fetch

Pull changes to current branch

git pull

Create branch

git branch <branch name>

Switch to branch

git checkout <branch name>

Publish new branch

git push --set-upstream <remote name (origin by default)> <branch name>

See the changes you have made

git diff

Save the current changes for later use (already tracked files)

git stash

Save the current changes for later use (untracked files)

git stash -u

Apply the last saved chanegs

git stash apply

Rollback to previos commit

//Safe way
git revert HEAD/<commit>

//Dangerous way
git reset

Merging one branch to another

git merge <branch name>

Merging one branch to another with merge commit

git merge --no-ff <branch name>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment