Git QuickRef


Clone a remote repository locally

  • cd to target directory
  • git clone <remote uri>

Change local branch

  • git checkout <branchname>

Create a local branch and Push to remote branch

  • git checkout -b <branchname>
  • git add .
  • git commit -m “commit message”
  • git push -u origin <remote-branchname>
  • e.g
    • git push -u origin master
    • git push -u origin dev

Overwrite all local changes from remote (origin)

  • git fetch –all
  • either:
    • git reset –hard origin/master
    • git reset –hard origin/<branchname>

Push same code to a second remote (skills421)

Delete a local branch

  • use -D instead to force deletion without checking merged status
  • git branch -d <branchname>
  • git branch -D master

Delete a remote branch

  • git push origin –delete <branchname>
  • e.g
    • git push skills421 –delete dev

Merge dev into master

  • git checkout master
  • git merge Dev
  • git checkout Dev

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

  • git branch -a # list all local and remote branches
  • git branch # list all local branches
  • git branch -r # list all remote branches

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

View Git Commits

git log

Advertisement

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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