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:
- Clone a clean copy of the repository (if you don’t already have one)
- Create the branch
- Switch over to the branch (you’ll still be on ‘master’ after creating it)
- Make the edits (or just copy the files over in my case)
- Commit
- 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.