Show the current status of your repo.
git status
Show a diff between your changes and what's in the repo.
git diff [filename]
Add files with changes to be committed.
git add filename
Add all changes to be committed.
git add .
Making commits.
-
git commit -m "Add my commit message"
-m Specify a commit message
Unstage a file.
git reset filename
Unstage all changes.
git reset HEAD
Show the commit log.
-
git log
-n Show the last n commits
--oneline Make the log more readable
git push
git push -u origin my-branch
git pull
does a git fetch
followed by a git merge
.
If you don't want to merge a remote branch then simply git fetch some-branch
.
Fetching is useful getting a remote branch for the first time, while pulling is useful for getting the latest changes.
-
git pull -r
-r Incorporate changes by rebasing instead of merging. Helps prevent useless merge commits.
List all branches.
git branch
Checkout a branch.
-
git checkout my-branch
-b Create and checkout a new branch
-
git checkout master
-
git merge my-branch
For rewriting history on branches only you work on. This allows for cleaner and more helpful commit history.
Important: Never rewrite history on a branch someone else pushes / pulls from.
Interactively rebase the last n
commits.
git rebase -i HEAD~n
Stash changes for later use when your not ready to commit.
git stash
Stash your changes with a meaningful name.
git stash save "My half-completed feature"
List all stashes.
git stash list
Apply changes from a stash.
git stash apply stash@{n}
Delete a stash.
git stash drop stash@{n}
List your remote repositories.
-
git remote
-v Verbose
Tell Git to ignore specific files and directories by specifying it in .gitignore
touch .gitignore