0% found this document useful (0 votes)
18 views

Setting Up Your Environment For Git Interacting With Your Local Git Repo

This document discusses setting up Git on a local machine and interacting with a local Git repository. It covers initializing a new repository from an existing directory, cloning an existing remote repository, and basic Git commands like add, commit, status, and diff. It also discusses reverting changes and going back to previous snapshots in the repository's history. The next topic to be covered is using GitHub and working with remote repositories in Git.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Setting Up Your Environment For Git Interacting With Your Local Git Repo

This document discusses setting up Git on a local machine and interacting with a local Git repository. It covers initializing a new repository from an existing directory, cloning an existing remote repository, and basic Git commands like add, commit, status, and diff. It also discusses reverting changes and going back to previous snapshots in the repository's history. The next topic to be covered is using GitHub and working with remote repositories in Git.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

In this lecture, we will discuss

Setting up your environment for Git


Interacting with your local Git repo

Git Setup
Setup properties globally
$git config --global user.name Kalman Hazins
$git config --global user.email [email protected]

Git Setup
Verify that an option has been set
$git config <option>
For example, $git config user.name

Getting help on any Git command


$git help <command>

Initializing a Repo
Where do I get a repo from?
1. Create a new repo

$cd workding_dir
$git init
(Possibly create a .gitignore file)
$git add .
(. Adds the entire current directory with subdirectories)

$git commit -m Initial commit

Cloning a Repository
2. Clone an existing repo (for example from Github)
$git clone https://repourl.git
Many transfer protocols available

https:

git:

git status
$git status
Provides the current status of your repo

git add
$git add <file/dir>
Add untracked file(s) to be tracked or
Add a modified tracked file to the staging area

Mods made to the file after git add need to be gitadded again even if you did not commit yet

git diff
$git diff
Shows the difference between staging and working
directory

$git diff --staged


Shows the changes between HEAD (latest commit on
current branch) and staging directory

$git diff HEAD


Shows the deltas between HEAD and working dir

git commit
$git commit
Commits your changes to the repo
Prompts for a commit message in an editor

Better, just use the -m (message) option


$git commit -m Your msg here

Skipping the Staging Area


To skip the staging area - just use -a flag
After initially adding the file!!!

Either -a -m or -am will do the trick

Going Back in Time


Before committing
$git checkout .
Re-checkout all tracked files overwriting local changes

$git checkout -- <file>


Re-checkout just one specific file

After committing
$git revert HEAD
Reverts the most recent commit

Summary
You have to add a file for tracking at least once before it
can make it into the repo
Can easily go back in time to a snapshot
Whats next?
Github and remote repositories in Git

You might also like