Basic setting
- Set global user information
git config --global user.name "your name"
git config --global user.email "your email"
- Set user information for current repository
git config user.name "your name"
git config user.email "your email"
Start
- Create a new repository in current directory:
- Create a new repository with some directory:
- Clone an existing repository:
git clone <path to repository>
git remote add origin <server>
Add and remove files
- Add all files in the working directory:
- Remove a file from both the staging index:
- Remove a file from both the staging index and the working directory:
git commit -m "commit message"
Push
git push <remote server> <local branch>:<remote branch>
- Push to the current branch’s remote:
- Push the current branch to the configured upstream:
- Push to the master branch:
Pull
git pull <remote server> <remote branch>:<local branch>
- Pull from the current branch’s remote:
- Pull the current branch from the configured upstream:
- Pull from a remote branch:
Branch operations
- List all (local and remote) branches:
- Create a new local branch:
- Create a new local branch and switch to it:
- Switch to a local branch:
git branch -m <old branch> <new branch>
git push origin --delete <branch>
- Merge a branch to the current branch:
Others
git rm -r --cached .
git add -A
git commit -m "update .gitignore"
git push origin master
- Abandon a local change of a file:
- Abandon all local changes
git fetch --all
git reset --hard origin/master
git pull
References