Clone a remote repository locally

cd to target directory

git clone 

This remote repository is the origin referred to in all subsequent git commands

Change local branch

git checkout 

Create a local branch and Push to remote branch

git checkout -b 

This will leave your current branch as is, create and checkout a new branch and keep all your changes

git add 

This will add changes to the new branch

git commit -m "commit message"

This will commit the changes to the new branch

git push -u origin 


git push -u origin master

(the master branch)

git push -u origin dev

(a branch off master called dev)

This will push the changes to made to the origin from which you originally cloned your project and to the specified branch on that origin

Overwrite all local changes from remote (origin)

git fetch --all

Then, you have two options:

git reset --hard origin/master

OR If you are on some other branch:

git reset --hard origin

Push same code to a second remote (skills421)

git remote add skills421
git push -u skills421 master

git push  :

Delete a local branch

use -D instead to force deletion without checking merged status

git branch -d somebranch
git branch -D master

Delete a remote branch

git push origin --delete somebranch
git push skills421 --delete somebranch

Merge Dev into master

git checkout master
git merge Dev
git checkout Dev


git remote add self file:///path/to/your/repository
git push self Dev:master

Destructively overwrite change history with current commit

git branch Phase1 $(echo "commit message" | git commit-tree HEAD^{tree})
git checkout Phase1
git branch -D master
git checkout -b master

Push to origin and reset to very top of tree, replacing all history

git push origin +master

List remote repositories for current local

git remote -v

List branches

list all local and remote branches

git branch -a

list all local branches

git branch

list all remote branches

git branch -r

Change Remote Branch being tracked

Branch master set up to track remote branch master from skills421
want to change it to track origin

git branch master -u origin/master

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s