Git and GitHub: Revision Control¶
Git Tutorials Playlist¶
Below are my lectures on git. It is a playlist of videos. Watch them all.
Set you name and email. Make sure the email you use is also listed in your github account.
git config --global user.name "Your Full Name" git config --global user.email "firstname.lastname@example.org"
If your email in git does not match one of the emails associated with your github account, then when you push and look at the log in github your commit will not have an avatar and your name will be be clickable. If you see that blank next to your commit it means you did it wrong. Setup your git email as above. Make sure the same email address is one of the ones in your github profile. Then do another commit and push it. Make sure you now get an avatar and you can click on your username.
When you are learning git for the first time, I recommend everyone simply use the master branch. Just make sure you frequently commit+pull+push your changes. Many teams do this for the entire first semester (490) as they get comfortable with git.
Android Studio, WebStorm, other JetBrains IDEs¶
The playlist below explains how to use the JetBrains IDEs for git and github. Watch them if you are using Android Studio, or WebStorm, or PyCharm, or any one of the Jetbrains IDEs. They are all very similar when it comes to git.
The git commands you need are the following.
To create a branch named
git branch jmvidal
To checkout my branch
git checkout jmvidal
git checkout master git pull
To merge the
jmvidal branch into master, without doing a
Pull Request at GitHub, we do:
git checkout master git pull #this should be a fast-forward merge git merge jmvidal git push
To share my branch with others, so they can see what I am doing now
git checkout jmvidal git push
To pull in my teammate's branch from github to my laptop, the first time I do
git checkout --track origin/his-branch-name
I now have a branch called his-branch-name in my laptop which tracks the same named branch at github. Later on, if he adds more changes to his branch, pushes them, and I want to download them, I just:
git checkout his-branch-name git pull
To delete my local
jmvidal branch do:
git branch -d jmvidal
To delete my tracking branch
git branch -d -r origin/jmvidal
To delete my
jmvidal branch at github do (this can also be done at
github.com with just a click)
git push origin --delete jmvidal
More advanced git tips¶
If you are in the middle of something, don't want to commit, but want to pull in the master branch just stash your code and pop it later. Assume that we are in the jmvidal branch, then:
git stash #stash away everything, even my un-committed changes git co master git pull #do what you need to do, then when you are done git stash pop #bring back my un-committed changes.
You have changed some files but decided all those changes are wrong. You just want everything to go back to where you where on your most recent commit. Simply
git reset --hard</pre>
git clean -fd
You did one or more commits that you regret, you want to get rid of them and just go back to a previous time. First find the commit you want to go back to using
git log commit 87c379822da3bb45e37ac20b633ef75a03b7c92a ...other info commit c3c0ecc10f968807b8cde449ec64907b79780a02 ...other info commit 5da03e94098a7d59f3586ea07ff7b4276b6fa4f3 ...other info commit 0318d2b5642dc01a359dbdc325e74f24d674634b</pre>
git reset --hard 5da03e94
Your current branch and HEAD will now be at 5da03e94. It will be like the other two commits never happened.
Cloning the github wiki¶
To clone the github wiki git repo (that is, your wiki) locally you just
.wiki in the repo name. For example, if the repo is called
and you use:
git clone email@example.com:SCCapstone/demo.git
git clone firstname.lastname@example.org:SCCapstone/demo.wiki.git
To add images, just add them in a new directory and then push. see this stackoverflow question for details.
- The GitHub Guides have lots of video and text tutorials.
- GitHub Learning Lab has interactive lessons for learning git and GitHub.
- Udacity has a free online class on How to Use Git and GitHub.
- Read the Pro Git book. If you read it now, you will save yourself years of misery and depression. Also, you will be able to 'commit' without fear and, thus, pass this class.
- Learn Git Branching is an interactive site that teaches you how branching and merging work.
- GitHub also has video tutorials on GitHub integration with various IDEs.