Most used Git commands for collaboration

4 April, 2022
134 read  ·  1 Hearts

Here is the list of most helpful and used Git commands. Use it as a cheatsheet.

Show remote: git remote

Show remote details: git remote -v

Add remote upstream from GitHub project: git remote add upstream

Add remote upstream from existing empty project on server: git remote add upstream ssh://[email protected]/path/to/repository/.git

Fetch: git fetch upstream

Fetch a custom branch: git fetch upstream branchname:local_branchname

Merge fetched commits: git merge upstream/master

Merge automatically accepting the changes made to the current branch git pull --strategy recursive -X ours origin master

Merge automatically accepting the changes made to the current branch git pull --strategy recursive -X theirs origin master

Remove origin: git remote rm origin

Show remote branches: git branch -r

Show all branches: git branch -a

Create and checkout branch from a remote branch: git checkout -b local_branchname upstream/remote_branchname

Compare: git diff origin/master..master

Push (set default with -u): git push -u origin master

Push: git push origin master

Force-Push: git push origin master --force

Pull: git pull

Pull specific branch: git pull origin branchname

Fetch a pull request on GitHub by its ID and create a new branch: git fetch upstream pull/ID/head:new-pr-branch

Clone to localhost: git clone or: git clone ssh://[email protected]/~/dir/.git

Clone to localhost folder: git clone ~/dir/folder

Clone specific branch to localhost: git clone -b branchname

Delete remote branch (push nothing): git push origin :branchname or: git push origin --delete branchname

Programming Git github github copilot programming programming languages Git commands
Comments  ·  0
You need to be Logged in to Comment. Login

More from @algosource


Need Help? ·  About
Terms and Conditions ·  Contact ·  Privacy

© 2021 ayedot. All Rights Reserved.