Git Commands Flashcards
Create a new local repository
git init
Send changes to the master branch of your remote repository:
git push origin master
Switch from one branch to another:
git checkout
Push all branches to your remote repository:
git push –all origin
Fetch and merge changes on the remote server to your working directory:
git pull
List the files you’ve changed and those you still need to add or commit:
git status
Pull down the latest changes from the remote server WITHOUT merging them into your branches quite yet.
git fetch
Apply all the changes from one branch to your current branch. You do NOT want to merge, merely apply everything that has changed (You don’t want a merge message in the history).
git rebase BRANCH-TO-PULL-CHANGES-FROM
You created a new local branch and want to push it to the server, but it doesn’t exist on the server yet. What is the command to create it and push it to the server at the same time?
git push origin BRANCH
Create a new branch and switch to it all in one command.
git checkout -b NEW-BRANCH
You are finished with a local branch you were using for testing. Delete it.
git branch -D BRANCH
You are completely done with a branch you were testing. You already removed it from your local computer. Delete it from the remote server.
git push origin :BRANCH
*Notice the colon “:”
You just merged to master and would like to increment the version. Example: that merge puts the product at v0.2.0. Use git to officially tag the release version.
git tag -a v0.2.0 -m “version 0.2.0. My message goes here”
*Make sure you have checked out the right branch.
You’ve properly tagged the application as v0.2.0. But it’s only a local tag. Push your tags to the remote server.
git push –tags
You’ve made a few changes, but don’t want to keep them. You would like to reset all your changes back to what they were when you first checked out your current branch.
git checkout .