what ARE the proper steps to merging in github?

what ARE the proper steps to merging in github?

Moderator: Content Developer

Post Reply
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

what ARE the proper steps to merging in github?

Post by smoth »

I was having a damnable time of it these past few days. At first I didn't say anything but by monday I was read to go and throw my chair through the window... So what is the proper way of merging?
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: what ARE the proper steps to merging in github?

Post by Forboding Angel »

Most merges happen automagically (fast forward). Rarely you will have a merge conflict, but if you do, it can be frustrating to understand merge tools. I know you have tortoise git installed so you also have tortoise merge. Tortoise merge basically shows the changes to what is in the remote repo and what is in your local repo. Essentially you just have to tell it what you want to keep, and order it properly. It takes some practice, but it is easy.

What fast forward is basically doing, is taking your changes in stride, and literally applying each commit in sequence (of course this happens VERY quickly). Because of this method, merge conflicts are pretty rare.

If you're talking about merging branches, that's simple. Just switch over to the master branch, and do

git merge <branchname that you want to merge into master>

It is different form svn in that git stores EVERYTHING in a single .git folder in the root of your local repo. Here are the changes for every branch. SVN plasters .svn in every single folder of the project, which can make for nightmarish conditions if your repo gets messed up.

It is important to understand that git is very little like svn. You can't transplant terms, because they generally don't mean the same thing in git as they do in svn.

Anyway, so lets say I have branch master, and I get a call that something is severely fucked.

Ok, well I don't want to contaminate my master branch with potential crapola, so I make a new branch for the hotfix

git checkout -b hotfix (the -b tells git to make a new branch... don't worry about having tons of branches, it's messy but it won't hurt anything and you can delete them easy as pie)

Ok, you will notice in your term window, it will have the branch name that you are using in parenthesis

Image

You can hot switch branches instantly using git checkout <branchname> so you can hop back and forth to your hearts content which allows you to test a shitload of branches all at the same time.

So anyway, we have our new file edited, and we want to commit it and test it on the hotfix branch

git commit -am "Testing my new hotfix"

Now we do the testing.

Testing is excellent now we want to merge hotfix into master

git checkout master

git merge hotfix

Bam, you're done, all that is left is to push it to the remote repo

git push origin master


In reality, it's about a 5 to 10 second process. It takes far longer to explain it on paper than it does to actually do it :-)


https://git-scm.com/ is an amazing and easy to understand encyclopedia of all things git. I have never hit a situation that I could not handle in git. I cannot tell you how many times I've had to wipe out a repo in svn just to fix stupid stuff.

A sidenote, in git you should usually NEVER need to rebase. Also, look up git stash. Git stash is one of the most useful tools ever.

As I said in the chat, I have a SUPER easy git setup for windows. It's FAR easier than the tortoisegit setup you are using now, and you will spend much less time and frustration fighting git. Git simply isn't meant to be used via a gui, and it's function simply doesn't work well when put into a gui.

Tortoisegit and tools like it are far more complicated than the 6 simple git command lines you'll need to remember.


Pretty much the only commands you'll probably ever need to use in git:

git clone
git checkout
git pull
git commit (-am)
git stash (you don't have to know this one, but it's freaking awesome)
git merge

Those are probably the only commands you'll ever need to use in git, and any time you need a command that isn't on that list, google it, because chances are you'll need that other command once in a blue moon.

Hope all this helps. Git really is simple. The problem is that when you come from svn, it makes the learning curve 5x as bad. Svn is a bad tool and it teaches awful development habits (this is something you never really fully appreciate until you are familiar with git).
User avatar
Silentwings
Posts: 3720
Joined: 25 Oct 2008, 00:23

Re: what ARE the proper steps to merging in github?

Post by Silentwings »

Git simply isn't meant to be used via a gui, and it's function simply doesn't work well when put into a gui.

Svn is a bad tool and it teaches awful development habits (this is something you never really fully appreciate until you are familiar with git)
I am familiar with git, due to using it everyday as my generally preferred method of version control, but think both the above statements are bollocks.
smoth wrote:pms etc etc
For using command line git to resolve a merge conflict, https://help.github.com/articles/resolv ... mand-line/ looks good.

As asked, here's how to use svn for LD: Use the web checkout address, e.g. https://github.com/SpringCabal/LD34.git as the checkout url in e.g. Tortoise SVN, and everything will work seemlessly as normal svn. To checkout just one subfolder/branch, use e.g. https://github.com/SpringCabal/LD34.git/trunk as checkout url.

The github<->svn bridge doesn't support some of the more complicated features of git, submodules etc, but for something like SpringCabal (where we barely even utilize the "proper" basic functionality of git, never mind the obscure stuff) you won't notice. The big iron solution is ofc to learn command line git, for simple projects github desktop is intuitive and worth a look, but is Win/Mac only iirc. They do both achieve nicer automagical merging than svn does, at the expense of being able to work with folders individually. Based on the commit log, it always seems to be you that had to do the merge, which is unlucky ;)
User avatar
Silentwings
Posts: 3720
Joined: 25 Oct 2008, 00:23

Re: what ARE the proper steps to merging in github?

Post by Silentwings »

Moved to (shiny new) LD subforum.
User avatar
PicassoCT
Journeywar Developer & Mapper
Posts: 10450
Joined: 24 Jan 2006, 21:12

Re: what ARE the proper steps to merging in github?

Post by PicassoCT »

You do not merge anywhere, but in your local repository..

The Trick is first to get it free of changes.
For this- this your changes have to either git revert ed git stash ed or git commit ed.

if you enter git status - you want to read a -is up to date on revision Nr .

You now git pull

If you have a commit, git will pull the recent commits from the remote and then inflict your changes upon them. This is a git rebase.

If there are no conflicts git will tell you upon git status that you are commits ahead of the remote.
You can git push

If you have merge conflicts, you resolve them, by either selecting in the files your revision or the one of the head.
You have to git add the files again, after you merged them to mark the conflicts as resolved.
If git did a rebase - git status will display too you that the git rebase was held - type git rebase --continue to
finnish the rebase.

git has flaws- in particular if you want to ignore files that have become part of the hash (even if you delete them, one wrong commit resurects the zombies)
but its damn good at version controlling - and god have i cursed it at times.

Definitely better then sitting sweating together with a coworker on a monday morning sorting out a merge gone sour, while your inbox fills with howling curses, cause everyone pulled a broken build from the svn repo.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: what ARE the proper steps to merging in github?

Post by Forboding Angel »

There is a command of rebase that I can't remember off the top of my head that will revert your changes and then do a fast forward where it applies the changes to master and to yours in sequence, which pretty much usually avoids merge conflicts.

Merge conflicts are usually pretty rare and when they do happen, they are generally minor. No, git isn't perfect, but the list of things that it can't do is extremely short.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: what ARE the proper steps to merging in github?

Post by smoth »

Thanks guys, I am feeling really ill so I cannot read and retain anything today. I hope that the information in this thread can be useful to others who also run into the issues I had
User avatar
Jools
XTA Developer
Posts: 2816
Joined: 23 Feb 2009, 16:29

Re: what ARE the proper steps to merging in github?

Post by Jools »

I wonder how you do with git to "fork" just one file, say a gadget, from another repo to your own. Do you need to first clone/fork the whole repo, then make a branch of it with all other things removed, and then merge with your home repo. It sounds complicated.

But what if there's one general version of a gadget, let's say, and that one is always blue. And you want to include that gadget and sync with future changes, but you want the gadget to instead be green. Is that possible?
Forboding Angel wrote:No, git isn't perfect, but the list of things that it can't do is extremely short.
You know this statement is mathematically untrue. For all things really, the list of things it cannot do is infinite, and in that list is the ability to make a list of things you cannot do :)
Post Reply

Return to “Ludum Dare”