How to get a git Remote branch, and how to merge.

By North Street, A Creative Studio

Normally, when you grab a repo, you’ll do a git clone, something like this:

git clone [email protected]:northstreetcreative/REPONAME.git

Typically that’s all you need. However, you may find that on very large projects, or projects with things in-process, you actually need to be working on a branch.

Clone by default, only gets you the master branch. To get the remote branch, you’ll need to do something similar to the following:

git checkout -b BRANCHNAME origin/BRANCHNAME

Where “BRANCHNAME” is the name of the branch. Note that after executing that command, you’ll be on the BRANCHNAME.

To see what branch you’re on, use

git branch

Which will output something similar to to this:

  master
* BRANCHNAME

At this point, you can continue working on whatever branch you need to work on.

git add . && git commit -a -m "Some message here"
git push origin BRANCHNAME

Now, at some point you’ll want to merge that branch into the master branch. I typically use branches when I’m developing a new feature and testing it out. Once it’s ready to go live, I merge the branch and then push it to the dev server, test again, then the live server.

To merge, first checkout the master branch. “checkout” is how you switch between branches:

git checkout master

Once you’re on master, it’s good practice to makes sure you have the latest version, so do another git pull

git pull origin master

Now, while you’re on the branch you want to merge INTO (master), you type:

git merge BRANCHNAME

This will take the changes from BRANCHNAME, and apply them to master. Hopefully everything works great. However you may find yourself with a merge conflict that adds lots of >>>>>>>> into some of your files. Git is unsure which file is the one it’s suppose to use, so it puts both bits of conflicting code into your file. You’ll need to resolve the errors, then recommit to finish the merge.

About north street

We engineer the thoughtful transformation of great organizations. Our proven process helps us understand what your competitors are doing right — and wrong. Want to learn more? Let’s chat.

More Notes

Team Spotlight: Matt Potter, Web Designer

Postcards from Puerto Rico: North Street Retreat ’22

We’re Hiring: Marketing Coordinator