Github Basics

GitHub

Sandbox GitHub repository is created and linked to in the artifact

Brandon: git clone

LaToya: git clone

Sandbox repo includes a .gitignore file with at least a few patterns included

Brandon: git ignore

LaToya: git ignore

Sandbox repo has at least one pull request

LaToya: pull request

Clone a remote repository

$ git clone https://github.com/USERNAME/REPO.git

Stage files for commit

$ git add . #to add all the files that have been updated

-or-

$ git add [name_of_specific_file]
$ git add main.css #individual file only

Unstage files

$ git rm --cached <file> # makes git stop tracking the file completely

-or-

$ git reset HEAD <file> # unstages any modifications made to the file since the last commit

Create a commit with a commit message

$ git commit -m "Initial Commit"

Amend the most recent commit message

$ git commit --amend

Create branches

$ git checkout -b [name_of_your_new_branch]
$ git checkout -b test1

Delete Branch

$ git branch -D [name_of_your_new_branch]

Push to a remote repository

$ git push origin master # git push [remote-name] [branch-name]

Pull a feature branch from a remote repository

$ git pull [options] [repository] #git pull is short for git fetch

Push a local branch to a specific remote branch

$ git push -u origin [branch-name]

Revert files back to a specific commit

$ git checkout [commit hash] -- file1/to/restore file2/to/restore

-or-

$ git checkout [name_of_branch]
$ git revert HEAD~2 #git revert should be used to undo changes on a public branch, and git reset should be reserved for undoing changes on a private branch.

Rebase a branch onto master

$ git pull --rebase origin master

-or-

$ git rebase [basebranch] [topicbranch]

Interactively rebase using the –interactive flag to squash, rename, and reorder commits

$ git rebase -i

-or-

$ git rebase --interactive

Move specific commits between different branches with the cherry-pick command

$ git cherry-pick [commit01]..[commit99] #Accepts a range of values

-A few popular options-

$ git cherry-pick --continue
$ git cherry-pick --quit
$ git cherry-pick --abort

Leave a comment