Skip to content

Instantly share code, notes, and snippets.

@wwwbruno
Last active June 29, 2016 08:10
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wwwbruno/4f7b7e3e616ae8187238 to your computer and use it in GitHub Desktop.
Save wwwbruno/4f7b7e3e616ae8187238 to your computer and use it in GitHub Desktop.
Git basic commands
# HELP
git help
git help config # get help for config command
git help commit # get help for commit command
# BASICS
git init # starts a new git repo
# FILES AND STAGE
# status
git status # show the modefied files and the files on the stage
git diff # show all file's change from the last commit
git diff file_name # show the file's change from the last commit
git diff --staged # show all file's change on the stage
git reset file_name # remove file from stage
# add and remove
git add file_name # add a file to the stage
git add directory # add the directory and all it's file to the stage
git checkout -- file_name # discart file's change on stage
# commit, pull and push
git commit -a -m 'My commit' # add and commit all files in one command
git commit -a -m 'My commit' file_name # add and commit the file in one command
git commit -m 'My commit' # commit the files in the stage
git commit --amend -m 'My commit' # amend (join) the actual stage to the last commit
git reset --soft HEAD^ # undo the last commit, but keep the changes
git reset --hard HEAD^ # undo the last commit, and discart the changes
git push origin master # push the commits to the 'origin' remote in the 'master' branch
git push -u origin master # push the commits to the 'origin' remote in the 'master' branch and save it as default remote
# REMOTES
git remote add origin git@wwwbruno.com:wwwbruno/example.git # add 'git@wwwbruno.com:wwwbruno/example.git' as 'origin' to the remotes
# FILES
git log # Show all the commits
# CONFIG
# config name
git config user.name = 'Bruno Almeida' # config user name for the actual repo
git config --global user.name = 'Bruno Almeida' # config user name for all the repos
# Config email
git config user.email = 'bruno@disvolvi.com' # config user e-mail for the actual repo
git config --global user.email = 'bruno@disvolvi.com' # config user e-mail for all the repos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment