Init: Initialize a repositoryStatus: Show current changes and staged filesAdd: Add files to staging areaCommit: Write changes to local repositoryCheckout: Move to another point in the revision treeDiff: Compare two points in the treeLog: Review history
- Using the terminal create an empty directory (
mkdir <FOLDER>) - Enter it (
cd <FOLDER>), and rungit init. What happened? - Run
ls -al, what do you notice?
- Create some text files inside the directory (
nano <FILE>) - Run
git status. What is the output? - Run
git add <filename>, and thengit statusagain, what changed? - Run
git commit -m "created my first file", what happened? - Run
git statusone more time. - Modify the file, and run
git status - Run
git diff <filename>, what is the output? - Run
git commit -a -m "changes to my file", what happens? What does the-ado? - Make more changes and commit them
- Run
git log, what is the output? We refer to those funny numbers as<commit hash>. - Run
git diff <commit hash>, what is the output? what does the color code tell you? - Run
git checkout <commit hash>, then look at the directory, what happened? - Run
git checkout master, what happened?, how could this be useful?
Go into your GitHub account and create a new repository (green button at the right side). Don't initialize the repository, follow the instructions on the next step to import an existing repository, the one you just created.
- Make some changes to the local repository and commit them.
- Run
git push. What happens? - Check your repository on GitHub
- Make some changes to your project using the GitHub interface (for example edit a README.md).
- Run
git pull. What happened?
- Do some changes locally, commit them, but don't push.
- Do some changes in GitHub and commit them.
- Now try to push from your local copy, what happens?
- Try to pull from your local machine, what happens?
.gitignore is a very special file, probably one of the most important. It is a file thet tells Github (in this case) what kind of files not to upload. For instance, those files that end in .pth, .png, .whatever, or even entire folders (like the datasets you use or the weights of the models you train).
Here is one example .gitignore file:
# ignore all .a files
*.a
# but do track lib.a, even though you're ignoring .a files above
!lib.a
# ignore all files in the build/ directory
build/
# ignore doc/notes.txt, but not doc/server/arch.txt
doc/*.txt
# ignore all .pdf files in the doc/ directory and any of its subdirectories
doc/**/*.pdf
- Go into the lab repository (https://github.com/BCEM-UniAndes/git-guide), and fork it (button at the top right), what happened?
- In your machine run
git clone <github url>, to clone your copy of the lab repository. - Run
git remote, what is the output? - Can you see the commit history?
- Can you make changes?
If you don't have push permission to a repository, you can ask the owner to pull changes from your fork. This is called a pull requests.
Branches lets you split work more efficiently, for example to develop different features independently or to work in teams. Branches can be created at any point, and can then be merged together, possibly requiring conflict resolution.
- To create a branch run
git checkout -b <branch name> - To switch between branches use
git checkout <branch name> - To merge branches use
git merge
GitHub is a web service that provides git on the cloud.
-
It is free for open source projects.
-
Provides a web based interface for several git tasks. Specially interesting
- Blame
- Diff
- Branching
- Pull Requests
-
Makes collaboration easier
-
Makes it easier to contribute to open source projects
-
An student package is available. It provides 10 free private repositories among other benefits https://education.github.com/pack
-
Additional features:
- Issue Tracker.
- GitHub Pages.
- Wiki.
-
Used by... everyone...
- Big companies (facebook, google, microsoft, uber, etc).
- Small companies.
- Students.
- Professionals.
- Open Source Projects.
- Hobbyists.
-
Becomes part of your portfolio.
-
Usually tech companies will see your gitHub profile.
- BitBucket
- GitLab
- GitHub for windows, mac
- Smartgit
See a more complete list at https://git-scm.com/downloads/guis
-
Just enough git to be less dangerous http://eev.ee/blog/2015/04/24/just-enough-git-to-be-less-dangerous
-
Friendly GitHub guide: http://readwrite.com/2013/10/02/github-for-beginners-part-2
-
Interactive tutorial: https://try.github.io
-
Video: http://youtu.be/lbLdbvIMHvw
-
Short guide: http://rogerdudler.github.io/git-guide/
-
Long guide: https://www.atlassian.com/git/tutorials/
-
Highly technical guide: http://git-scm.com/docs/gittutorial