Tag Archives: git

Git useful commands

Repositories

List remote repositories

Add new remote repository

In case of fork, it’s useful to add the original repo as a remote repo named ‘upstream’

Sync fork repo with original repo

First, fetch original repo

Then, switch to fork/branch to sync with original branch (eg. master)

Merge original/branch with fork/branch

Finally, push synced fork/branch in remote fork/repo (eg. master)

Branches

List Branches

only local branches

both remote-tracking and local branches

Create new branch and switch to new Branch

Command

Clone a specific Branch

Command

Create local Branch linked to remote Branch

Command

example

After you hit return the following happens:

Switch Branch

Command

Remove Branch

remove local branch

remove remote branch once removed local branch

Push changes to Branch

Command

Merge Branches

swithc to destination branch
than commit selected branch into current branch
–no-ff option generate a merge commit with a message

Tags

List Tags

Command

Create Tag

Command

commit id be retrieved via:

example

Push Tag

Push all tags

Push a single tag

Undo

Discharge changes on file or restore deleted file

Undo a commit

reference

git – la guida tascabile

Git repo: update forked with original

  1. Open terminal in fork folder
  2. Add the original repo calling it “upstream”
  3. Fetch all the branches of that remote
  4. Check out your fork’s local master branch.
  5. Merge the changes from upstream/master into your local master branch. This brings your fork’s master branch into sync with the upstream repository, without losing your local changes.

Reference: https://help.github.com/articles/syncing-a-fork/