Git Branch and pushing local branches to Github

I’ve been getting better at using Git in smart ways, but recently I did something a bit dumb. Instead of branching my code to port over to a different chip, I just make a copy of it into a directory not under version control. The issue I have now is how to add it to the repository as a separate branch. Since I’m not too far away from where I started, the answer is simple:

I’m going to create a new branch and replace the controlled files with the ones I previously edited. This is done with the following steps:

  1. Clone a clean copy of the repository (if you don’t already have one)
  2. Create the branch
  3. Switch over to the branch (you’ll still be on ‘master’ after creating it)
  4. Make the edits (or just copy the files over in my case)
  5. Commit
  6. Explicitly push the local branch back to remote (if you’re using a remote repository like Github)
git clone git://RepositoryAddressGoesHere
git branch newBranchName
git checkout newBranchName
nano fileToBeModified  #Modify the files any way you wish here
git commit -a -m "Commit Message"
git push origin newBranchName

That’s it. I made a new branch, altered a file, and commited it to that branch, then pushed the change to the remote repository. There’s a lot more about working with branches at the Git Book.

essential