- Git - version control software
- Repository - a folder containing your files and also containing a structure that helps keep track of changes in those files. When you intialize a repository, git creates a hidden folder (
.git
folder) that stores the changes to those files. - GitHub - a place to host git repositories and collaborate
- Local Repository - the version of a git repository on your local computer
- Remote Repository - the version of a git repository stored somewhere else that your local repository is connected to (frequently on GitHub)
- Commit - the basic unit of a git repository is a commit. It is a set of changes to a file. A commit usually comes with an id as well as a commit message that describes the change.
Within a Repository you have
- Untracked Changes - files that are in your folder but that git doesn't pay attention to.
- Staging Area - a place where you can put files before you commit them. Once files are in the staging area, git is paying attention to them.
- Commit Log (aka Git History) - all of the commits (previous changes) to all of the files in your repository.
- The working directory
git init
creates a git repo inside current working directory
- The staging area
git add .
adds changes from the working directory to the staging areagit add <filename>
adds changes to filenames specified from the working directory to the staging area
- The commit
git commit -m "commit message"
adds changes in staging area to the repositorygit log
shows
Protip: Run git status
after each command in the beginning because it allows you to visualize what just happaned.
- Your Github Page
- Social Features
- github - a service that hosts git remote repositories, and provides a web app to interact / collaborate on them
- remote - another repository that can be syncronized with a remote
- upstream - the name for a remote read-only repository
- origin - the name for a remote read-and-write repository
- clone - download an entire remote repository, to be used as a local repository
- fetch - downloading the set of changes (commits) from a remote repository
- pull - fetching changes and merging them into the current branch
-
Create 🍒🍎🍌🍇🍑🍉🍍 basket
cd ~/Development/ mkdir fruit-basket cd fruit-basket echo "i am cherry" > cherries.txt echo "i am a strawberry" > strawberries.txt echo "i am a watermelon" > watermelons.txt
-
Initialize repository
git init git status git log
-
Add the fruits to the staging area.
git add cherries.txt git add strawberries.txt git add watermelons.txt git status git log
-
Create a commit.
git commit -m "add cherries, strawberries, and watermelons" git status git log
-
Create a blank github repo called "fruit-basket".
-
Set your remotes (follow the instructions in the new github repository, it should look something like below).
git remote add origin [email protected]:XXXXX/XXXXX.git git push --set-upstream origin master
-
Push the commit.
git push git status git log
-
Backup the
assignments
directory. -
cd into your directory
~/Development/assignments
-
run
pwd
andls
to remind yourself where you are and what is there -
intitialize a git repository in the folder. Your shell prompt (
PS1
) should also show that we are now in a git repository.git init git status git log
-
Add day 1 homework to the staging area.
git add sayhello.py git add expensive_water.csv git add expensive_water_summary.txt git add description.txt git add output.csv git add summary.txt git status git log
-
commit
git commit -m "add day 1 homework" git status git log
-
create a blank github repo called "assignments"
-
set your remotes (follow the instructions in the new github repository, it should look something like below)
git remote add origin [email protected]:<username>/<repo>.git git push --set-upstream origin master
-
push your commits
git push
-
check if the code is pushed online
-
cd into your directory
~/Development/universe
-
run
pwd
andls
to remind yourself where you are and what is there -
intitialize a git repository in the folder
git init git status git log
-
add mars.txt
git add solar_system/planets/mars.txt git status git log
-
commit
git commit -m "add mars" git status git log
-
add earth
git add solar_system/planets/earth git status git log
-
commit
git commit -m "add earth" git status git log
-
create a blank github repo called "universe"
-
set your remotes (follow the instructions in the new github repository, it should look something like below)
git remote add origin [email protected]:XXXXX/XXXXX.git git push --set-upstream origin master
-
push your 2 commits
git push
-
check your repository online by refereshing the page in github
- Add
venus.txt
and commit it with the message "add venus". - Add
jupiter.txt
anduranus.txt
and commit it with the message "add jupiter and venus". - Add the rest of the
planets
folder and commit it with the message "add remaining planets". - Add the rest of the
stars
folder and commit it with the message "add stars". - Run
git status
to check for any more "untracked files". Add the remaining files and commit them. - Push these commits to github.
-
Clone code4policy repository.
git clone [email protected]:dmil/code4policy.git
-
Dhrumil will now push a commit.
-
Run
git pull
followed bygit log
to see the new commits.
Git is a distributed version control system (VCS). Distributed means that there is no one central server that stores all of your code- you can have redundancies (copies) of the code wherever you like. There is always one copy of the code (along with its entire history) on your local computer. Other copies of your code are each referred to as "remotes". Github.com is a very popular remote used for Git projects such as it is almost synonymous with Git now. There are of course other alternatives such as BitBucket and GitLab.