Difference between revisions of "Git"

From HalfgeekKB
Jump to navigation Jump to search
 
Line 1: Line 1:
 
'''git''' is a source code management and versioning tool that differentiates itself from CVS and svn (while aligning with [[bzr]]) in being distributed: Exclusive locks aren't really a thing and most activity occurs off the network.
 
'''git''' is a source code management and versioning tool that differentiates itself from CVS and svn (while aligning with [[bzr]]) in being distributed: Exclusive locks aren't really a thing and most activity occurs off the network.
 +
 +
==Starting a server repo==
 +
 +
Use the <code>--bare</code> option. This starts a repo without a working copy, which is what you want on a server.
 +
 +
===Create new, empty repo===
 +
 +
<syntaxhighlight lang=bash>
 +
cd ~/$parent_subdir
 +
mkdir $project_name
 +
cd $project_name
 +
git init --bare
 +
</syntaxhighlight>
 +
 +
===Clone existing repo===
 +
 +
<syntaxhighlight lang=bash>
 +
cd ~/$parent_subdir
 +
git clone --bare $existing_repo_url $project_name
 +
</syntaxhighlight>
 +
 +
===git URL===
 +
 +
If the above is done by <var>$username</var> on an SSH server <var>$hostname</var>, the resulting git URL is
 +
 +
$username@$hostname:$parent_subdir/$project_name
  
 
==Undoing changes==
 
==Undoing changes==

Revision as of 07:02, 15 February 2016

git is a source code management and versioning tool that differentiates itself from CVS and svn (while aligning with bzr) in being distributed: Exclusive locks aren't really a thing and most activity occurs off the network.

Starting a server repo

Use the --bare option. This starts a repo without a working copy, which is what you want on a server.

Create new, empty repo

cd ~/$parent_subdir
mkdir $project_name
cd $project_name
git init --bare

Clone existing repo

cd ~/$parent_subdir
git clone --bare $existing_repo_url $project_name

git URL

If the above is done by $username on an SSH server $hostname, the resulting git URL is

$username@$hostname:$parent_subdir/$project_name

Undoing changes

Git is complex enough that there are several semantically distinct ways to undo work.

This flowchart by gitforteams.com gives a rundown of which one is appropriate for your situation.

vs. bzr

The single most confusing thing about git, if you're coming from bzr, is that your working copy typically encompasses multiple branches, rather than only one as normal in bzr. You list these with

git branch

and switch to one named foo with

git checkout foo

If you have a place you want your code to end up (like bzr push --remember), you set up a remote:

git remote add remotename repo-URL

Then you make it remember the "upstream branch", which is what remote and what branch to use when pushing:

git push -u remotename branch

When committing everything that's changed, you basically do

git commit -c

If there are changed files you don't want to commit, you add them (which in bzr is something you only do with files that aren't watched yet) and don't add the files to be left behind.

git add files
git commit # no -c

"git revert" doesn't do what "bzr revert" does. Do this instead:

git checkout . # Restore files as committed