Cloning a Repository



• When you clone a repository, files are copied to a folder in the location where you run the command

git clone <uri>


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Create a Local Branch



• When you create a branch on your local repository, you are creating a safe place for you to make changes to the repo cloned
• Any changes made to the “master” branch on the remote server can easily be pulled down to your computer

# Create a new branch "mycode" with -b swtich
git checkout -b mycode


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Keep Local Repository Up-to-Date



# Sync with remote repository
git fetch


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Making Changes



# Check status
git status

# What is changed
git diff


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Revert Changes



Scenario #1: Revert changes made to 1 file



# Restore the file to its last committed version
git checkout <file path>


Scenario #2: Revert changes made to several file

s

# Restore changes made to several files to last committed version
git reset --hard


Scenario #3: I created a branch to experiment with some changes, and now I just want to throw the whole thing out



# Delete a branch
git branch --delete --force <branch name>


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Commit Changes



• You need to tell Git who you are before you can commit any changes to a repository (one-time setup)

# One-time setup of username and email address
git config --global user.name "Your name"
git config --global user.email your@email.address.com
# or
git config --global --edit


# git add: Add files/ dir from Working Directory --> Staging Area

# Add a file
git add <file>

# Add certain file types
git add *.html

# Add all files & directories
git add -A
# or
git add .


# Commit
git commit -m "Put remark/message here"


# Reset author after Commit
git commit --amend --reset-author


# Commit made will be writtent to log
git log

Index