- Initialize a local Git repository
- Create a local copy of a remote repository
git clone ssh://git@github.com/[username]/[repository-name].git`
- Add a file to the staging area
- Add all new and changed files to the staging area
git commit -m "[commit message]
- Remove a file (or folder)
git rm -r [file-name.txt]
- List branches (the asterisk denotes the current branch)
- List all branches (local and remote)
git branch -d [branch name]
git push origin --delete [branch name]
- Create a new branch and switch to it
git checkout -b [branch name]
- Clone a remote branch and switch to it
git checkout -b [branch name] origin/[branch name]
git branch -m [old branch name] [new branch name]
git checkout [branch name]
- Switch to the branch last checked out
- Discard changes to a file
git checkout -- [file-name.txt]
- Merge a branch into the active branch
- Merge a branch into a target branch
git merge [source branch] [target branch]
- Stash changes in a dirty working directory
- Remove all stashed entries
- Push a branch to your remote repository
git push origin [branch name]
- Push changes to remote repository (and remember the branch)
git push -u origin [branch name]
- Push changes to remote repository (remembered branch)
git push origin --delete [branch name]
- Update local repository to the newest commit
- Pull changes from remote repository
git pull origin [branch name]
git remote add origin ssh://git@github.com/[username]/[repository-name].git
- Set a repository’s origin branch to SSH
git remote set-url origin ssh://git@github.com/[username]/[repository-name].git
git log` | View changes |
- Preview changes before merging
git diff [source branch] [target branch]