Git

From HalfgeekKB
Jump to navigation Jump to search

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.

Setting the difftool/mergetool program in the Windows version

In Windows, I changed the local comparison tool to Meld like this:

git config diff.tool meld
git config difftool.meld.path "C:\Program Files (x86)\Meld\meld\meld.exe"
git config merge.tool meld
git config mergetool.meld.path "C:\Program Files (x86)\Meld\meld\meld.exe"

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