-
Notifications
You must be signed in to change notification settings - Fork 16
Useful Git Commands
git status
List changes since last commit.
git add .
Tracks any untracked files, and adds all modified files to next commit.
git rm file
Deletes file and stages it for removal in git. Just using rm will not remove the file from your repository unless you run the command below.
git add . -A
Same as git add ., plus deleted files in local repository will also be deleted on the remote (if you used rm instead of git rm).
git commit -m "Message"
Commit all added files, if git add was used.
git commit -a -m "Message"
Automatically add and commit all modified files. Unlike git add ., will not track untracked files.
git merge branch0
Merges branch0 into the current branch (and auto-commits).
git push origin branch0
Pushes all commits of the current local branch to remote branch0.
git branch
Lists all local branches.
git branch branch0
Creates local branch0
git branch branch0 origin/branch1
Creates local branch0 tracking remote branch1 (they usually will have the same name).
git branch -d branch0
Deletes local branch0.
git branch -D branch0
Force deletes local branch0. Use with caution, may result in data loss.
git checkout branch0
Switch over to branch0.
git pull
Get any changes from the remote and sync with your local repository.
Merge a finished feature to develop
git checkout joe-dev: Switch to joe-dev branch
[do stuff here]
git add .: Add all modified files to next commit
git commit -m "Implemented feature X": Commit all added files
git push origin joe-dev: Sync local commits with the remote branch joe-dev
git checkout develop: Switch over to the develop branch
git merge joe-dev: Merge the new stuff from joe-dev
git push origin develop: Sync local merge with the remote branch develop
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
