Skip to content

Instantly share code, notes, and snippets.

@SalvadorP
Last active November 15, 2022 20:15
Show Gist options
  • Save SalvadorP/d34a9cdc1cf68c4c81a11982240112ce to your computer and use it in GitHub Desktop.
Save SalvadorP/d34a9cdc1cf68c4c81a11982240112ce to your computer and use it in GitHub Desktop.
Own cheatsheet of useful git commands, different from commit, fetch, branch, ...

Git create branch

see where are we

git branch

make sure we are up to date

git pull

create the branch and change to it

git branch new_branch_name

git checkout new_branch_name

Git Renaming branch

git branch –m oldbranch newbranch

git push origin :oldbranch newbranch

git branch –-unset-upstream

Explanation

The last command will delete the old branch and push the new one.

The ":" on the push will mark to delete the branch on the remote repo. Similar to using -d when deleting locally a branch.

Another way…

git push origin :old-name-of-branch-on-github

git branch -m old-name-of-branch-on-github new-name-for-branch-you-want

git push origin new-name-for-branch-you-want

Check this for more information

http://www.w3docs.com/snippets/git/how-to-rename-git-local-and-remote-branches.html

Git updating branch with changes in master

git checkout branch_name

git fetch

git rebase origin/master

Git updating branch with changes of another branch

We have two branches, b1 has changes we want to merge in b2.

We put the repo in b2 and then merge the changes of b1.

Git checkout b2

Git fetch (optional)

Git merge b1

Git delete branch locally

git branch -d branch_name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment