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

Leave a Reply

Your email address will not be published. Required fields are marked *