Git: Difference between revisions

From Medien Wiki
No edit summary
 
(16 intermediate revisions by 3 users not shown)
Line 5: Line 5:
In order to use git, you need to have git installed on your computer, which is most likely the case if you're on a Mac or a Linux system. For all other cases, you can get git here: [http://git-scm.com/ git-scm.com].
In order to use git, you need to have git installed on your computer, which is most likely the case if you're on a Mac or a Linux system. For all other cases, you can get git here: [http://git-scm.com/ git-scm.com].


This page shows some common commands, but remember that most modern [[IDE]]s support versioning systems like git with an additional graphical user interface (in case of Xcode there's a code-timeline and built-in file merging capability).
This page shows some common commands, but remember that most modern IDEs support versioning systems like git with an additional graphical user interface (in case of Xcode there's a code-timeline and built-in file merging capability).


== Setup ==
== Setup ==
Line 19: Line 19:
<source lang="bash">git remote add origin ssh://myserver.com</source>
<source lang="bash">git remote add origin ssh://myserver.com</source>


For example, you can use [https://github.com/ github.com] to host your open source projects, or [https://bitbucket.org/ bitBucket.org]. You will find an excessive online help on how to setup a remote server on github: [http://help.github.com/set-up-git-redirect How-to-Setup github]. Basically, you only need a private/public ssh key and a valid user account.
For example, you can use [https://github.com/ github.com] to host your open source projects, or [https://bitbucket.org/ bitbucket.org]. You will find an excessive online help on how to setup a remote server on github: [http://help.github.com/set-up-git-redirect How-to-Setup github]. Basically, you only need a private/public ssh key and a valid user account.


But remember, you can use git only on your local computer as well, it is not required to have an online server!
But remember, you can use git only on your local computer as well, it is not required to have an online server!
Line 37: Line 37:
or to add all:
or to add all:


<source lang="bash">git add *</source>
<source lang="bash">git add .</source>




Line 47: Line 47:
At this point, your commit is only local! You can commit as few or as many changes as you like. But at the end of the day, you should push your changes to the server:
At this point, your commit is only local! You can commit as few or as many changes as you like. But at the end of the day, you should push your changes to the server:


<source lang="bash">git push origin master</source>
<source lang="bash">git push origin main</source>




Line 77: Line 77:




So: forget CVS and SVN, with GIT there's really no excuse to not use a versioning systems anymore.
So: forget CVS and SVN, with GIT there's really no excuse to not use a versioning systems anymore. There is also bazaar, which claims to be even easier than GIT, but isn't as widely adopted. Mercurial is another version control system which is becoming more and more popular.


== Summary ==


'''tl;dr'''
* git != github.com
** git is a local version control software. You have to install git locally on your machine
** then (!) you can (!) add remote git servers to your local repository. This is where github, gitlab, gutbucket & co (or your own git-server) come into the game
** but then again, git works fine just locally. You do not need to use a remote server, nor do you have to use github or any other service provider.
* the most important commands you want to remember are
** <tt>git init</tt>
** <tt>git remote add origin {ssh://myserver.com}</tt>'' (Add remote Server)''
** <tt>git status</tt>
** <tt>git add .</tt>
** <tt>git commit -a -m "minor changes"</tt>
** <tt>git push origin master</tt> ''(Push to remote Server; where 'master' is the name of your current branch)''
* you might want to use a git control software with a graphical user interface
** github.app supports git in general, not only github related repositories. Its nicely designed and really useable. Available for: [http://mac.github.com Mac], [http://windows.github.com Windows]) and [http://mobile.github.com Mobile] (mainly for github features)
** SourceTree as featured from Bitbucket, for [http://www.sourcetreeapp.com Mac] ... though I wouldn't recommend this to beginners.
** Many IDEs support git as well (Xcode, Coda, Textmate, Sublime via Plugin …), so you don't even need to leave your coding environment
* Commit very frequently!
** In fact, commit after every small step and try to be as accurate as possible on your commit messages.
* Branch!
** Whenever you want to try something or are faced with the need to add, change or delete more than one or two files: create a new branch. It's easy, lightweight and you can revert or merge at any point.
== Tutorial ==
An [[/Tutorial|(advanced) tutorial]], mainly based on input commands to set up a project with a remote server.


== Links ==
== Links ==


* [http://git-scm.com/ git-scm] - Official Project Page
* [http://git-scm.com git-scm] Official Project Page
* [http://gitref.org/ gitref.org] - Git Reference
* [http://gitref.org gitref.org] Git Reference
* [http://git.or.cz/course/svn.html gir.or.cz Crash Course] about git
* [http://git.or.cz/course/svn.html gir.or.cz Crash Course] about git
* [https://github.com/ github.com]  
* [https://github.com GitHub]
* [https://bitbucket.org/ bitBucket.org]
* [https://gitlab.com gitlab]
* [https://bitbucket.org Bitbucket.org] (Also works with Mercurial)
* [http://pcottle.github.io/learnGitBranching Learn Git branching] – nice interactive branching tutorial
 
== Literature ==
* [http://git-scm.com/book/ Pro Git Book], ISBN 1430218339, Available in many languages and as CC-BY-NC version in electronic formats (PDF, ePub...)


[[Category:Git]]
[[Category:Git]]
[[Category:Programmiersprachen]]
[[Category:Programmiersprachen]]
[[Category:Michael Markert]]
[[Category:Michael Markert]]
[[Category:HowTo]]

Latest revision as of 15:49, 11 January 2021

git is a distributed versioning & revisioning system. It can be used locally and remotely.

git automatically tracks all files that were changed and has the ability to synchronize the files to a remote server.

In order to use git, you need to have git installed on your computer, which is most likely the case if you're on a Mac or a Linux system. For all other cases, you can get git here: git-scm.com.

This page shows some common commands, but remember that most modern IDEs support versioning systems like git with an additional graphical user interface (in case of Xcode there's a code-timeline and built-in file merging capability).

Setup

With other revisioning systems, it can be quite a hassle to create an initial setup for a folder, with git this is really easy. Just open up your shell, change the directory to the directory you wish to use git and type:

cd myProjectPath
git init


To add a remote git server, type:

git remote add origin ssh://myserver.com

For example, you can use github.com to host your open source projects, or bitbucket.org. You will find an excessive online help on how to setup a remote server on github: How-to-Setup github. Basically, you only need a private/public ssh key and a valid user account.

But remember, you can use git only on your local computer as well, it is not required to have an online server!

Usage

to get the status of your local git repository, query:

git status


to add files you type:

git add myfile.ext


or to add all:

git add .


If you changed something and would like to store these changes as a version, you can "commit" your update:

git commit -a -m "comment about change"


At this point, your commit is only local! You can commit as few or as many changes as you like. But at the end of the day, you should push your changes to the server:

git push origin main


If you are interested in getting the changes from the server to your local machine, type:

git pull


That's all for the beginning!
Easy, isn't it?


Advantages

Setting up a versioning repository has many advantages, these are just a few:

With a local git repository, you always have:

  • multiple backups
  • the possibility to revert to any file state at any time
  • no fear to overwrite anything
  • merge changes

With an (additional) online repository, you can:

  • work with multiple people on the same project
  • work from multiple computers on the same project
  • merge changes
  • branch other projects (make your own copy)
  • send pull requests to the master branch: if you changed something and would like to contribute to the original project, you can easily request these updates


So: forget CVS and SVN, with GIT there's really no excuse to not use a versioning systems anymore. There is also bazaar, which claims to be even easier than GIT, but isn't as widely adopted. Mercurial is another version control system which is becoming more and more popular.

Summary

tl;dr

  • git != github.com
    • git is a local version control software. You have to install git locally on your machine
    • then (!) you can (!) add remote git servers to your local repository. This is where github, gitlab, gutbucket & co (or your own git-server) come into the game
    • but then again, git works fine just locally. You do not need to use a remote server, nor do you have to use github or any other service provider.
  • the most important commands you want to remember are
    • git init
    • git remote add origin {ssh://myserver.com} (Add remote Server)
    • git status
    • git add .
    • git commit -a -m "minor changes"
    • git push origin master (Push to remote Server; where 'master' is the name of your current branch)
  • you might want to use a git control software with a graphical user interface
    • github.app supports git in general, not only github related repositories. Its nicely designed and really useable. Available for: Mac, Windows) and Mobile (mainly for github features)
    • SourceTree as featured from Bitbucket, for Mac ... though I wouldn't recommend this to beginners.
    • Many IDEs support git as well (Xcode, Coda, Textmate, Sublime via Plugin …), so you don't even need to leave your coding environment
  • Commit very frequently!
    • In fact, commit after every small step and try to be as accurate as possible on your commit messages.
  • Branch!
    • Whenever you want to try something or are faced with the need to add, change or delete more than one or two files: create a new branch. It's easy, lightweight and you can revert or merge at any point.

Tutorial

An (advanced) tutorial, mainly based on input commands to set up a project with a remote server.

Links

Literature