Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Git Commands
# To initialize a Git repository here, type the following command:
git init
# To get the current state of our repository
git status
# To Add files to staging area
git add filename.ext
git add *.java
# To add files to commit from staging are with appropriate message
git commit -m "This is my commit message"
# To view commit history in log pages
git log
# To add local repository with remote repository. If local repo is not already cloned from remote repository.
git remote add origin
# To push local repo commits to remote repo
git push -u origin master
# To get remote repo changes into local repo
git pull origin master
# To get difference between commits
git diff HEAD
# To get difference between staged files
git diff --staged
# To get unstage file but still keep the changed file
git reset myfilename.ext
# To get file versioned as in last commit
git checkout myfilename.ext
# To create branch from master
git branch my_new_branch_name
# To switch between branches
git checkout master
git checkout my_new_branch_name
# To remove file from repo as well as from disc
git rm myfilename.ext
# To Merge one branch into other branch
# First Checkout target branch
git checkout mytargetbranch
# Now merge your souce into checked out target branch
git merge mysourcebranch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment