Showing posts with label GIT. Show all posts
Showing posts with label GIT. Show all posts

Saturday, November 13, 2010

GIT branching and merging

Further useful git things about branching and merging: To list your existing branches:


$git branch


To check out visually what your branches are doing:


$gitk


To create a branch:


$git branch newbranchname


To change to a certain branch:


$git checkout branchname


To merge the changes made in the branch "branchname" into the current branch:


$git merge branchname


After merging the branch is not deleted automatically. To delete it:


$git branch -d branchname


To undo a merge:


$ git reset --hard HEAD


Merge branch obsolete into the current branch, using ours merge strategy:


$ git merge -s ours obsolete


Take out of source control some directories:

$ git rm -r --cached Somefolder/bin

Sunday, September 26, 2010

Setting up GIT

I have an ASP.NET MVC hobby project I am doing on my own but still a source control system is useful. After looking around I have choosen GIT. I have used already CVS, SVN, VSS, TFS and perforce but I have read good things about GIT, so I have thought that I might as well try it out. Well, I have never set up a source control system and I am not a linux guru either so I have pretty much spent my whole day with this (but as usual it is 10 minutes if you know how to do it). My setup is the following: I want to have a git remote repositry on a Linux desktop and I am developing on a Windows laptop. So for this scenario to set up, you kind of have to do the following: On the linux machine:
  • Install GIT (it is written here how, but if you are so dumb with Linux as I am then I tell you that "su" is the command to become root)
  • Create a directory where you want to have your repositry.
    mkdir gitrep
  • Add write and execute writes recursively for everyone.
    chmod -R 777 gitrep
  • Initialize the git bare repository
    git init --bare
  • In your git repository in the .git fodler open up description file and give the repository a description (for me the push has failed without this, I do not know why....)
On the Windows machine do the following:
  • Install git there as well (it is written here how)
  • Go to the directory where your project is in Windows Explorer and right click and say GIT bash here. From now on everyting goes into git bash. So type in:
    git init
  • Add your project
    git add .
  • Commit your project
    git commit -m "Initial commit"
  • Set up a remote: as far as I understand a remote is a git repository that is not your current repository. You can use a file share or like me connect to the remote repository via ssh (there are of course other options too....).It is a convention to call the remote origin.
    git remote add origin ssh://user@ipaddress/~/gitreponame
  • So now everything is set up, let us push:
    git push origin master
  • To test out that my thing is really in the remote repository I have quickly created a new folder with git init and added the same remote. Then I have said:
    git pull . remotes/origin/master
  • And yes everything was there copied. :)