Sat 17 August 2013
Git is a version control system (VCS).
Note: For some reason the ass clowns at Github quietly put in support for large files, so you have to install an extension to github. If you don't, it can be painful to work with github from the command line.
brew install git-lfs
Git Cheat Sheet
|Init||git init||Start a repository|
|Clone||git clone git://somewhere.com/something.git [new_name]||Create a copy of a repository|
|Remote||git remote -v||Display remote repository|
|Push||git push origin [master]||Share changes to an upstream remote (origin) for a branch|
|Commit||git commit -m 'update'||One step add/push upstream|
|Add||git add *.c||Add files to the repository or to stage files for commit|
|Fetch||git fetch [origin]||Pull all changes from a remote repository that have been pushed since you cloned it. Note this doesn't merge any of the changes.|
|Pull||git pull||Will automatically fetch and merge changes from upstream into current branch|
|Tag||git tag -a v1.4 -m 'my Version 1.4'||Create an annotated tag, note you may have to: git push origin v1.4 or git push origin --tags to get tags push on upstream server.|
|Status||git status||Reports the status of untracked changes in your working repository|
|Diff||git diff||Display changes between working directory and repository|
|Rm||git rm file.c||Remove files from repository|
|Mv||git mv from_file to_file||Move files|
|Log||git log||View the commit log|
Let's start off with making git look nice:
git config --global color.ui true
Since we will work remotely, we need to tell git who we are. Git stores that info in ~/.gitconfig
git config --global user.name "walchko" git config --global user.email firstname.lastname@example.org
Working with Git
First clone a repository, make sure you use the ssh address and not the default https one
git clone email@example.com:walchko/soccer.git
Note: The https one has https in the address: https://github.com/walchko/soccer2.git
if you accidentally clone the https one, you can switch to ssh by
git remote set-url origin firstname.lastname@example.org:walchko/soccer2.git
Now create ssh keys following the github directions
create a key: ssh-keygen -t rsa -C "email@example.com":
pi@bender ~ $ eval "$(ssh-agent -s)" Agent pid 12480 pi@bender ~ $ ssh-add ~/.ssh/id_rsa Identity added: /home/pi/.ssh/id_rsa (/home/pi/.ssh/id_rsa)
Go to github and add a new ssh key under your profile. Copy/paste in the key (use more ~/.ssh/id_rsa.pub) making sure not to add or remove white space. You can use pbcopy < ~/.ssh/id_rsa.pub to copy it to your clip board.
Then try to ssh in:
pi@bender ~ $ ssh -T firstname.lastname@example.org The authenticity of host 'github.com (126.96.36.199)' can't be established. RSA key fingerprint is 1d:57:ac:a4:76:23:2d:34:63:1b:56:4d:74:7f:76:48. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'github.com,188.8.131.52' (RSA) to the list of known hosts. Hi walchko! You've successfully authenticated, but GitHub does not provide shell access.
Success ... enjoy!
Read this awesome guide
Make sure your current copy is up to date
Create a new branch to hold your new feature
git checkout -b my-cool-new-thing
Edit your code. To see status:
git status On branch master Your branch is up-to-date with 'origin/master'. Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: docs/computers/git.rst no changes added to commit (use "git add" and/or "git commit -a")
Mark files for change
git add *
Commit files (locally) to HEAD
git commit -m "what did you do?" pi@bender ~/soccer/IMU $ git push origin master Counting objects: 12, done. Compressing objects: 100% (8/8), done. Writing objects: 100% (8/8), 736 bytes, done. Total 8 (delta 6), reused 0 (delta 0) To email@example.com:walchko/soccer.git 8162ade..cd9a476 master -> master
Push changes upstream, back to the repository so everyone can use them
git push origin master
or git push because origin master is the default.
Create a tag
git tag -a v0.5.3 -m "update" git push origin v0.5.3
To undo what you have committed already and basically create an anti-patch for each commit
git revert 0766c053 25eee4ca a867b4af
Sometimes you need to include another git in your project ... how do you do that?
git submodule add firstname.lastname@example.org:adafruit/Adafruit_Python_PureIO.git
This will include it. Now you can track development and update as necessary to the latest code. This will also add a .gitmodules to your project which will track what submodules (other git projects) you are tracking.
When you need to clone your project (and the submodules too) though, you now have to do:
git clone --recursive email@example.com:...
This will pull your project and any submodules your project has too.