Repository A log book for a captain
Commit How you put something in your diary - a single diary entry
Master The name for the default “universe”
Hunk A location in your code where Git has detected changes
Branch Parallel Universe
Master Branch Original version
Merge Put history of one branch into another
Origin Online parallel universe
HEAD Is a reference to the last commit in the currently checked-out branch.
Working Tree / Working Directory The actual files, with all the changes you’ve made, whether you have committed them or not
Staging Area / Index Intermediate collection of files and changes prepared to all be committed together. Useful for excluding some changes that you don’t want to commit just yet Ignore for now if you like
List
ls
List what is here
Change Directory
cd [directory]
Change to specified directory
cd ..
Change to the directory above. The double dots means 'directory above'
Where am I
pwd
Print working directory ... the directory we are in now.
** Make A New Directory**
mkdir [new directory name]
Make a new directory in the directory that you are currently in.
Copy
cp [original file] [new file]
Copy the original file to a file named what you specify in "new file" File specifications can include whole directories too: "/my_folder/file.txt"
** Move **
mv [original file] [new file]
Much like cp, but doesn't copy the file into a new one, just moves it.
Remove or Delete
rm [file] rm -r [directory]
Remove (or delete) a file or directory. This is permanent! Using the "-r" flag is necessary for directories
Configure your user name
git config --global user.name [My Name]
Lets git know who you are If you ever collaborate with others, this way people can know which commits are yours.
Configure your email
git config --global user.email [email protected]
Tell Git your email address Create a config file in your home directory
git init
Create that hidden .git directory so Git is ready to start working with your project.
git status
“Hey Git, what’s up right now?” Displays general information about your current repository.
Your Captain's Log or Diary
Add a File
git add [file]
Tell git to now keep records on a file so you can commit changes you've made to it.
Commit a Change
git commit -m “Commit message here”
Whatever changes you've made (and added to the staging area), commit them with the note or message provided after the "-m" flag.
Commit a Change without Adding to the Staging Area
git commit -a -m 'Added first verse'
The "-a" flag means: git-add, then do commit Only works for changes to files that have previously been added. If you want to commit changes to a new file, you have to add as above, then you can use the above.
Seeing your History
git log shows captain’s log activity
git log --oneline Show the git log in a more concise form.
Seeing Differences between changes or commits
git diff
Shows differences between current uncommitted changes and those of the most recent commit
Time Travel
Cancelling previous commits
git revert [unique change id]
The "Unique Change ID" is what the commands "git log" give you for each commit Cancels the changes made in a particular commit, and adds a new commit recording this reversal of changes
Going back in time to a previous commit
git checkout [unique change id]
Goes back to the state of your files at this commit Lets you look at your files as they were at this time, and run code if you need to
Going back to the present
git checkout master
Parallel Universes
List all Current Branches
git branch
Make a new Branch
git branch [branch name]
Go to a branch
git checkout [branch name]
Merge the History of a branch into the current branch
git merge [branch name]
Takes the history of "branch name" and merges that into the branch you are current in. Running "git branch" before, to confirm which branch you're in maybe helpful. If there are different changes in each branch that can't be merged, ie that conflict with each other, you will get a conflict that needs to be resolved.
Sharing your repositories online
List current Remotes
git remote -v
Add your GitHub (or other) repository to your local repository
git remote add [name] [URL]
Adds the URL of your online Repo to your local repo under the name you provide. Within Git, this is the name of the remote that you are using
Put your Local History onto your Online Repo
git push [remote name] [branch]
Takes all of the history of the branch you specify and adds it to the remote you specify This history is put into a branch of the same name as your local one, the one you specify.
Bring changes that are on your online repo into your local Repo
git pull [remote name] [branch]
Here, "branch" specifies the branch name in the GitHub account (which will generally be the same name as the one on your local computer, as it will have been created by you doing "git push" as above)
Will take the history of the "branch" on "remote name" and merge it into the branch you are currently in