Reef Rashid
Reef Rashid

Reputation: 59

Editing a branch in git?

I created a branch on the github website that wasn't in my local repository. How do I bring that branch to my local computer, edit it, and then push it back to my github account?

Upvotes: 2

Views: 4084

Answers (3)

Code Sloth
Code Sloth

Reputation: 1

You have to update your local files first. In your terminal:

  1. Run a git pull from your master branch
  2. git checkout (branch_name you created on github website)

Or

You can bring your codebase back to the exact commit of a branch you are talking about. In the repo under the specific branch you should see all of your commits. The number on the righthand side of each commit is the SHA number. You can copy this and then use the following:

git fetch origin SHA git checkout FETCH_HEAD

Upvotes: 0

tom
tom

Reputation: 22939

Run

git fetch

to retrieve the new branch from GitHub's server and then use

git checkout YOUR-BRANCH-NAME

to switch to that branch.

When you have committed your changes, push them to GitHub using

git push

See Git Branching - Remote Branches for more information.

Upvotes: 1

Ho Zong
Ho Zong

Reputation: 549

In your local workdir enter:

git fetch origin newbranch
git checkout newbranch

where newbranch is the name of your new branch. Then do your edits, and when finished do:

git push origin newbranch

Upvotes: 1

Related Questions