This is a very brief overview of installation and set up of git for reference. This isn’t for teaching you git. I’ve found that as I’ve taught people git these are the things I constantly had to look up or have them look up just for getting started. So I thought I’d make a brief overview of the steps to make everyone’s lives easier.
For information about git resources, including a book that can teach you all you want to know about git, I have a post about that here.
Important note: some of these steps are specific to the gitlab git server repository. If you are using a different repository check their documentation.
Git Installation Overview:
Basically all you need to do, for Windows, is download git from git-scm.com. Install git bash (which will be your command line interface), and git gui.
Git Set Up:
Set your user name and email. These “tag” your commits. In git bash:
git config --global user.name "John Doe" git config --global user.email firstname.lastname@example.org
At this point you can start using git locally. If you don’t have a git repository there is nothing further you need to do for set up. The rest of the article is for connecting to (in this case a gitlab repository) git repository to push (like SVN commit) and pull (like SVN update), and lots more for easy collaboration among your fellows.
Connecting to a Remote Repository
Create your SSH Keys (You can add multiple):
(Should match your email from above)
ssh-keygen -t rsa -C "email@example.com"
- The default place to save is correct (unless you’ve changed your settings) so just hit enter.
- If you want a passphrase enter it followed by an enter twice. Otherwise hit enter twice.
The ssh key will now be saved in your user folder under “.ssh”. By default in Windows this will be in your user’s directory. Open the idrsa.pub file and copy the whole thing.
Save the key in your repository.
In Gitlab go to:
My profile -> Add public key
paste the entire key in the “key” box. Title will auto fill.
Select “Add key”
You should now have ssh access to the git repository and will be able to push, pull, clone, etc.
Make/Update your server repository
If you have a blank project: Clone/create a new repository:
Navigate/create the directory where you want the cloned project to go. (For SVNers, this is like checking out a project.)
In general, to clone from a repository via ssh the command is:
git clone git@:/.git
For example project it’s this:
git clone firstname.lastname@example.org:john.doe/BestProjectEvah.git
Once that is done, you need to create a local repository and then tell local git where your origin is. Git won’t make an empty repository unless you tell it to. So make a dummy file and add it to the repository and push to origin and tell git to track the upline:
cd project_folder touch README.md git add README.md git commit -m "add README" git push -u origin master
If you have an existing project (but not a git repo)
cd existing_project_folder git init git remote add origin email@example.com:john.doe/BestProjectEvah.git git add . git commit -m "Initial commit" git push -u origin master
If you have an existing Git repository
cd existing_repo git remote add origin firstname.lastname@example.org:john.doe/BestProjectEvah.git git push -u origin --all git push -u origin --tags
The “-u” in the “git push” tells git to track the branch on the remote branch. In future pushes then you don’t have to tell git which branch on the origin to push to. Just do a “git push origin $branch_name”.
Update your remote url
Sometimes your remote url will change. (curse the techs right?! 😉 )
To check your remote url run
$ git remote -v
This will list any short name remotes along with their urls.
To update run:
$git remote set-url
If you need more details the
$ git remote set-url --help
is in fact very helpful.
Good luck! 🙂
Let me know if you find anything that is incorrect or other important startup commands to get going. I’m happy to refine. 🙂