Skip to content

Instantly share code, notes, and snippets.

@vikas-git
Last active December 8, 2019 13:17
Show Gist options
  • Save vikas-git/fafb6c813c8e40d7b778322fc8b28ecc to your computer and use it in GitHub Desktop.
Save vikas-git/fafb6c813c8e40d7b778322fc8b28ecc to your computer and use it in GitHub Desktop.
Git basic commands
# Git clone from specific branch
git clone -b my-branch git@github.com:user/myproject.git
# Before pushed code need to run given command..
git stash clear; git stash; git pull; git stash apply;
git commit files
git add .
git commit -m "udpate"
git push
for discard all changes is certain file
git checkout <filename>
# check file difference
git diff <filename>
# create duplicate branch from existing branch
# suppose currently I am in master branch and want to create dev branch.
git pull # to update my master branch
# Create the branch on your local machine and switch in this branch :
git checkout -b dev (new branch name)
# Push the branch on github server
git push origin dev
# check all created branch
git branch (it show all branches and current working branch)
# Create new branch from current branch
$ git checkout -b myfeature(new branch) dev(created)
- Creates MyFeature branch off dev. Do your work and then
$ git commit -am "Your message"
- Now merge your changes to dev without a fast-forward
$ git checkout dev
$ git merge --no-ff myFeature
- Now push changes to the server
$ git push origin dev
$ git push origin myFeature
# check who changed what and when in my_file :
git blame my_file
# check current git url :
git remote show origin
# To undo git add before a commit:
git reset <file> or git reset to unstage all changes.
# for revert last commit:
git reset --soft HEAD~1
# for delete certain branch
git push origin --delete test
# for merge code from dev branch to master branch
git checkout master # first go to master branch
git merge dev # merge from another branch
git push
# For more information read this article:
https://towardsdatascience.com/10-git-commands-you-should-know-df54bea1595c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment