List the current configurations:
git config --list
Setting the name you want attached to your commit transactions:
git config --global user.name "[name]"
Setting the email you want attached to your commit transactions:
git config --global user.email "[email address]"
Note: this should be your email associated with the git repository
git clone [url]
Note: use SSH url
Checking out an existing branch:
git checkout [branch-name]
Checking out a new branch:
git checkout -b [branch-name]
Listing all local branches:
git branch
Renaming current branch:
git branch -m [new-branch-name]
Note: this only works for local branches, do not do this if the branch was already been pushed
Deleting a branch:
git branch -d [branch-name]
Deleting a branch that has not been fully merged yet:
git branch -D [branch-name]
Note: sometimes you have to fetch
before your local repository knows the branch has been merged
Downloads all history from the repository:
git fetch
Pulling changes from the remote branch:
git pull origin [branch-name]
Pushing changes to the remote branch:
git push origin [branch-name]
Updating branch with current latest master:
git merge master
Note make sure that your local master is up too date with the remote one
Listing status of repository:
git status
Staging files to be committed:
git add [file]
Stage files interactively:
git add -p
To stage all files:
git add .
Note: you shouldn't be doing this
Unstaging a file:
git reset [file]
Committing:
git commit -m "[desciptive message]"
Note: keep you messages short
Amending a commit:
git commit --amend
Note: avoid amending commits that has already been push
Copying commit from another branch:
git cherry-pick [commit-has]
Undoing all changes after a commit, preserving the changes locally:
git reset [commit-hash]
Undoing last commit, preserving the changes locally:
git reset HEAD~
Note: include --hard
if you want to discard the changes
Listing the full version history for the current branch:
git log
Listing the version history up to a certain number of commits for the current branch:
git log -[number-of-commits]
Showing the current diff:
git diff
Showing the current diff for a file:
git diff [file-name]
Stashing current changes:
git stash
Restoring stashed changes:
git stash pop
Listing stashed changes:
git stash list
Discarding the stashed changes:
git stash drop
Note: avoid having multiple stashes