This is a compilation of notes, tips and a getting started guide to
git. Please feel free to open a pull request or fork it for yourself!
This is not meant to be a complete guide to git. Just some notes that I’ve gathered over the years of using git that might be helpful to share with others.
gitand install it.
gitavailable through a package manager like
pacman. That will be the easiest option.
git config --global user.name "Your Name Here"
git config --global user.email "email@example.com"
You’re ready to
git init. this command creates a
.gitfolder inside the current folder, which is where
gitstores all the information and history for the repo.
echo "foo bar" >> foobar.txt
git statusyou should see something like this:
git add foobar.txt) or all changes to the working tree with the command option
committhe changes. every commit requires a message, which can be specified with the
-moption. if you don’t give a message with the
gitwill open your file editor and ask you to enter one.
Now you have a repo with one commit in it!
Now we get to have some real fun. The whole point of a distributed version control system is to allow many people to be working on the same code at once.
There are many ways to collaborate on a
git repo. The simplest way to share a repo is to use the
--bare option with the
Bare repos are generally stored on a server that all users have SSH access to: once the repo is created on the server, each person can
clonea copy to their local machine like this:
git clone user@servername:path/to/repo
Otherwise, there are dozens of git hosting options, the most popular of which is github, which hosts the majority of all open source projects.
Another cool option is gitlab. They offer unlimited private repos in addition to public ones.
Let’s take a look at syncing your repo with github (or any other git hosting location - just swap out the URLs).
git remote add origin firstname.lastname@example.org:username/reponameOR
git remote add origin https://github.com/username/reponamedepending on your SSH key setup
clonethe repo like this:
git clone email@example.com:username/reponame
git remote -v
pushyour commit history to the remote repo! use this command:
git push origin --allto push all branches and commits to the remote (assuming that the remote is named
To get changes that have other people have pushed the the repo while you were away, use the
merge commands. since this is such a common operation,
pull was created as a shortcut for
git fetch immediately followed by
If you haven’t made any changes since the last time you
pulled the latest changes, it’s usually a good idea to
rebase. This will replay all of the work that has been done on top of the current repo state, avoiding extra merge commits in the repo history. Just use
git pull --rebase.
So you want to learn more? Here are some more resources!
Shoot me a message somewhere on the interwebz
Thanks for checking out my git guide!