Git basic
Initializing a Repository in an Existing Directory¶
File Status¶
Three Status¶
- Modified: the file has been changed but not committed yet
- Staged: a modified file is marked in its current version to go into your next commit snapshot
- Ommitted: the data is safely stored in local database
Checking the Status of Your Files¶
Short Status¶
There are two columns to the output — the left-hand column indicates the status of the staging area and the right-hand column indicates the status of the working tree
- File is modified in the working directory but not yet staged
- Modified, staged and then modified again
- New files that have been added to the staging area
- Modified and staged
- New files that aren’t tracked
Cloning an Existing Repository¶
Tracking/staging New Files¶
Viewing Changes¶
git diff() only shows changes that are still unstaged. If you’ve staged all of your changes, git diff will give you no output.
If you want to see what you’ve staged that will go into your next commit
Committing Changes¶
git commit
git commit -m "Story 182: fix benchmarks for speed" # (1)
git commit -a -m 'Add new benchmarks' # (2)
- Inline commit message
- Skip the staging area
Removing Files¶
Remove files from staging area¶
- If you modified the file or had already added it to the staging area, you must force the removal with the -f option
keep the file in your working tree but remove it from your staging area¶
Viewing the Commit History¶
Undoing Things¶
Working with Remotes¶
Remote repositories are versions of your project that are hosted on the Internet or network somewhere.
Showing Your Remotes¶
- Lists the shortnames of each remote handle you’ve specified
- Shows the URLs that Git has stored for the shortname to be used when reading and writing to that remote
Adding Remote Repositories¶
- The short name can be used to replace the full URL e.g.
git fetch pb
Fetching and Pulling from Your Remotes¶
git fetch command only downloads the data to your local repository — it doesn’t automatically merge it with any of your work or modify what you’re currently working on. You have to merge it manually into your work when you’re ready.
If your current branch is set up to track a remote branch , you can use the git pull command to automatically fetch and then merge that remote branch into your current branch.
Pushing to Your Remotes¶
Inspecting a Remote¶
Renaming and Removing Remotes¶
- rename pb to paul