Git is a version control software that allows us to save "snapshots in time" of files in a directory so that we can track changes over time and go back to previous versions if necessary.
Here is a list of the git commands I have learned so far:
- Action Commands
mkdir
makes a new directorytouch
creates a new filecd
changes directorycd ..
goes up one directory levelecho
adds text to a filecat
displays text from a filegit status
gives current status of a repositorygit init
initialzes git tracking in a directorygit diff
shows the changes (insertions/deletions) of filesgit add
adds files to the staging areagit commit
commits changes that have been made (snapshot in time)git push
pushes local changes to GitHub repogit pull
pulls remote changes to local repositorygit clone
downloads remote repository to local directorygit remote add origin
connects a local repo to a remote GitHub repo
- Informative Commands
pwd
prints the current working directoryls
lists all files in working directory
- Destructive Commands
rm
deletes a filerm -rf
deletes a directory
Here is a basic example of git workflow might look like. The code below will:
- create a directory with some files
- initialize git tracking
- add files to staging area and commit those changes
- edit the files
- add files to staging are and commit a second time
- connect to a remote GitHub repo
- and push those changes to GitHub
cd
mkdir my_foods
touch drinks.txt breakfast.txt lunch.txt dinner.txt # Step 1
git init # Step 2*
git add .
git commit -m 'Initial commit' # Step 3
atom . # Step 4*
git add .
git commit -m 'Started lists for each file' # Step 5
git remote add origin https://github.com/fentontaylor/my_foods.git # Step 6
git push -u origin master # Step 7
*Note:
- Step 2 instead of adding files individually, add . stages all unstaged files
- Step 4 is a shell command to use the atom text editor to make changes to the files. It is much more convenient to do this than to use
echo
to add text to files.
Git and GitHub are much more complex than this guide explains. I will be able to update it later with more examples of merging branches and dealing with pull requests later! The following git workflow diagrams gives a nice visual repreentation of the basics of using git and GitHub.