Shared repo:
git clone <repo>
git checkout -b <branch>
git add <dir>
git commit -m "<message>"
git push -u origin <branch>
# Submit "Pull Request" on GitHub.
# After accepted:
git checkout master
git pull
git branch -d <branch>
Fork & Pull:
git clone <repo>
git remote add upstream <upstream repo>
git fetch upstream # Keep
git checkout master # local repo
git merge upstream/master # updated.
git checkout -b <branch>
git add <dir>
git commit -m "<message>"
git push -u origin <branch>
# Submit "Pull Request" on GitHub.
# After accepted:
git fetch upstream
git checkout master
git merge upstream/master
git push -u origin master # Push changes to folked master.
git branch -d <branch>
# Git Basics
git init <dir>
git clone <repo>
git add <dir>
git commit -m "<message>"
git status # List which files are staged, unstaged and untracked.
git log # List entire commit history.
git diff # Show unstaged changes between index and working directory.
# Git Branches
git branch # List all branch.
git branch <branch> # Create a branch.
git checkout -b <branch> # Create and check out a new branch.
git branch -d <branch> # Delete a branch. The branch must be fully merged.
git merge <branch> # Merge <branch> to the current branch.
# Remote Repos
git remote add <name> <url> # Create a new connection to a remote repo.
git remote fetch <remote> <branch> # Fetch a <branch> from the repo. Leave out <branch> to fetch all.
git pull <remote> # Fetch the specified remote’s copy of current branch and merge it into the local copy.
git push <remote> <branch> # Push the branch to <remote>. Creates <branch> in the remote repo if it doesn’t exist
# Git Config
git config --global user.name <name> # Define the author name to be used for all commits by the current user.
git config --global user.email <email> # Define the author email to be used for all commits by the current user
# Git Log
git log -<limit> # Limit the number of commits by <limit>.
git log --oneline # Condense each commit to one line.
git log -p # Display the full diff of each commit.
git log --stat # Display altered files and the relative number of lines that were altered.
git log --author="<pattern>" # Search for commits by a particular author.
# Git Diff
git diff HEAD # Show difference between working directory and last commit.
git diff --cached # Show difference between staged changes and last commit.