zigford.org

About | Links | Scripts
Sharing linux/windows scripts and tips

Git - Working with branches

August 06, 2019 — Jesse Harris

In this quick article, I will:

  • quickly create a branch on a git repository.
  • make some commits
  • push them to a remote branch
  • clone to a new location (to simulate working on another machine)
  • merge the new branch to master
  • delete the local and remote branches

Reminder - This site is mainly for my memory and reference. You can find this information anywhere out on the web, but I find the best way to remember something is to write it down yourself.

Firstly, clone a repo and cd into it.

make a new local branch

    git checkout -b updates/onedrive

Now, make some commits and we will push this to a new remote branch like this:

push to remote branch

    git push -u origin updates/onedrive
    

note, the remote and local branch names need not match
second note, -u stands for --set-upstream-to

Next, go to another computer where you will resume work. (or for the sake of practice, just clone again to another directory) On the new clone, we need to fetch all other branches

download all branches

    git fetch origin

create a local branch, pull the remote branch to it

    git checkout -b updates/onedrive
    git pull origin updates/onedrive
    

Here we can examine the branch, continue to make changes and commits. If we want to push back to the remote branch, we need to set the upstream:

    git push -u origin updates/onedrive

When we are done, perhaps we want to merge the changes back to master. In that case:

merge changes to master

    git checkout master
    git merge updates/onedrive

Now would be a good time to push changes. Then you can delete the local and remote branches.

delete local branch

    git branch -d updates/onedrive

delete remote branch

    git push --delete origin updates/onedrive

I hope this information helps me, let alone you!

Helpful links

stackoverflow
stackify
git-scm.com
freecodecamp.org

Tags: git