Git Command Reference

Create a new git repository:

git init

Add a file to staging (index):

git add <filename or directory>

Enter and interactive staging add where you can choose portions a file to commit:

git add -p

Commit changes to HEAD:

git commit -m "Comments to include about this commit"

Add new changes to the most recent (latest) commit:

git commit --amend

Change only the last commit message:

git commit -amend -m "Here is my new shiny updated commit message"

Change most recent commited files without changing message (avoid as this can be very confusing to merge down later):

git commit -amend --no-edit

Take uncommitted changes (both unstaged and staged) and store them away for later:

git stash save "Descriptive message of changes being stashed"

Redoing stashed changes:

git stash pop

Redoing stashed changes, but keeping them in stash:

git stash apply

View all of the commit changes:

git show

View all of the commit change logs:

git log

Look at differences between working copy and index:

git diff

Update the username and email address used in commenting entries:

git config --global user.name "First Last or Alias"

git config --global user.email "myaddress@test.com"

Remote repository

How to clone (download) a git repository on your local machine:

git clone <remote path to .git file>

How to push to remote repository:

git push

How to pull from remote repository:

git pull

How to remove remote origin from local git repository:

git remote remove origin

Additional Resources

https://www.atlassian.com/git/tutorials/learn-git-with-bitbucket-cloud

https://www.tutorialspoint.com/git/git_basic_concepts.htm

Share this: