Skip to content

Instantly share code, notes, and snippets.

@mahamuniraviraj
Created July 23, 2017 22:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mahamuniraviraj/37f6a225232a480a5d16e90dec63b8f4 to your computer and use it in GitHub Desktop.
Save mahamuniraviraj/37f6a225232a480a5d16e90dec63b8f4 to your computer and use it in GitHub Desktop.
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 https://url_of_remote_repo.com/username/mygitrepo.git
# 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