GIT for beginners guide. GIT tutorial for subversion users

By neokrates, written on July 2, 2010

article

Rate it
  • 1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 4 out of 5)
    Loading ... Loading ...
Ad
Poll
  • Which features are most important for perfect CI tool?

    • Something else (70%, 7 Votes)
    • Parallel builds (20%, 2 Votes)
    • Simple usage (20%, 2 Votes)
    • Simple to extend (10%, 1 Votes)
    • Good support (10%, 1 Votes)
    • Large community with lots of plugins (10%, 1 Votes)
    • Available know-how (simple to find specialists to support your projects) (0%, 0 Votes)
    • Good integration with other enterprise tools (0%, 0 Votes)
    • Open source (0%, 0 Votes)
    • Free tool (0%, 0 Votes)
    • Established standard, popularity (0%, 0 Votes)
    • Most advanced features (0%, 0 Votes)

    Total Voters: 10

    Vote

    Loading ... Loading ...
Feeds:
  • bodytext bodytext bodytext
Most popular search terms:

We begin with one empty GIT remote repository. Repository is called “test-repo” and located under “test-project” project in Gitorious . We will pay no attention to the server side here. We just use the Url to work with remote repo.

 
Normally, work with Git starts with clone. For Svn user, that is like checkout, we get the source we need. I you have no git, you want to get it first.

Software:

[v] Git 1.6.3.3
[v] Ubuntu 9.10
[v] Gitorious

Should also work for:

[v] Other Git versions git 1.6.3.3
[v] Other Linux distros and versions
[v] Any git remote server like Gitosis

1

Get git

Under Linux distros you can simply do:

sudo apt-get git-core

 

(After I installed it I got with dpkg -l: git-core 1:1.6.3.3-2 )

Second option is to go to http://git-scm.com/download and take the newest.

2

Checkout (clone) repository

You need the full Url of remote repository. Given it is your.git.server:test-project/test-repo.git, you do:

git clone [email protected]:test-project/test-repo.git test-repo
cd test-repo

3

git status = svn info

Git status shows the state of your local repository and much more. With status you can learn a lot about Git repository you work on.

git status

 
You get:

# On branch master
nothing to commit (working directory clean)

 
That is, your local repository and remote are the same and there are no local changes.

4

git add = svn add

Create test file:

echo "hallo" > my-file

 

Trygit status now:

# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# my-file

 
Git complains that there is new file and suggest that you add it. That action in Git is called “to stage”.

git add test.file

 
To add all changes, do:

git add .

  [i] svn:

svn add my-file

 

git status:

# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: my-file

 
Git knows about new file and you can commit or reset it.

5

git reset = svn revert

You have just “staged” my-file. If you didn’t actually want to commit anything you can go back:

git reset my-file

 
Now you can do some great things with the file or just remove it. In our case we append the file and add it once more:

echo "hali-hallo" >> my-file
git add my-file

6

git commit = svn commit (“to local repo”)

git commit my-file

 
[i] svn:

svn commit my-file



[i] Remark:
After Svn commit, central repository has the file. In Git, only local repository has the file. Remote (central) repository knows nothing about it after you commit.

git status:

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
nothing to commit (working directory clean)

 
Here, Git states that your ‘local repository’ is ‘ahead’ of the ‘origin/master’. That means, that your commit didn’t change the master state.

7

git push = svn commit (“to central repo”)

git push

 
That will get changes from your local repository to the ‘central’.
[i] Svn does not have this step, all changes go directly to the central repo.

git status:

# On branch master
nothing to commit (working directory clean)

 
nothing staged, local and remote repos are the same…

8

git rm = svn rm

git rm my-file

  [i] svn:

svn rm my-file

 

git status:

# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# deleted: my-file
#

 
You can do git commit my-file or git reset my-file as you please now.

9

Remove remote origin

Maybe your team lead has changed the Git repository location or you need to give your Git project more suitable remote location … First you remove the “current origin”

git remote rm origin

 

10

Add remote origin

Can be done for example after “remove remote origin” so that you can work against new remote Url.

git remote add origin [email protected]:project/new-repo-url.git

 

Git push doesn’t seems to work after that, with message like:

warning: You did not specify any refspecs to push, and the current remote
warning: has not configured any push refspecs. The default action in this
warning: case is to push all matching refspecs, that is, all branches
warning: that exist both locally and remotely will be updated. This may
warning: not necessarily be what you want to happen.
warning:
warning: You can specify what action you want to take in this case, and
warning: avoid seeing this message again, by configuring 'push.default' to:
warning: 'nothing' : Do not push anything
warning: 'matching' : Push all matching branches (default)
warning: 'tracking' : Push the current branch to whatever it is tracking
warning: 'current' : Push the current branch
Everything up-to-date

 
You can now use following to push:

git push origin master (or git push --all)

 
That’s is, have fun! :)

 

LEARN MORE (amazon bookstore)

TAGS

RELATED
Pages
Posts
    nope :(

SOCIAL
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • BlinkList
  • Blogosphere News
  • E-mail this story to a friend!
  • Furl
  • LinkArena
  • Live
  • MisterWong
  • Print this article!
  • StumbleUpon
  • Technorati
  • Webnews.de
  • YahooMyWeb

INCOMING SEARCH TERMS


Leave a Reply