I am a very basic git user; I basically only use the commands git add -a
(to add files after modifying them) and then git commit -m "what I did"
and then git push
(to push it to my server).
Now I want to do something very drastic to my codebase. Something that might possibly not work -- and I will have to revert back to where I was.
How do I do that? Do I create a "branch"? Or a tag? Or something else?
I am after a set of simple commands with simple explanations. also to then return to the original HEAD, or to then (maybe) merge the changes into HEAD (which won't have changed)
Merc.
You need a branch.
git checkout -b nameofyournewbranch
This checks out your current branch (default name is 'master') as a new branch with the name you specify. Any commits you do now will be on the new branch. If you want to leave it and go back to where you were:
git checkout master
to go back to your new branch:
git checkout nameofyournewbranch
if you want to merge your branch into your main codebase:
git checkout master
git merge --no-ff nameofyourbranch
--no-ff means you will see it branch out of master and then branch back in, allowing you to keep track of separate features.
To see what you're doing, get a git source tree viewer of some sort e.g. source tree, gitk etc. Much easier to understand what the branches are doing if you can see them visually.
Update: To check what would happen before merging, make a temporary branch in the same place as master and merge to there:
git checkout -b tempbranchname master
git merge --no-ff nameofyourbranch
If you like it, merge it to master and it'll be as if you did it on master in the first place:
git checkout master
git merge tempbranchname
If you don't, just delete it:
git checkout master
git branch -D tempbranchname
-D means delete even if not merged to master. Use -d normally as you'll get a warning if you try to delete unmerged stuff that you would lose.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With