Originally this repo started to house basic git commands. Recently I am adding my notes as I go through this course from Andrew Brown of ExamPro.
-
Repository (repo): Represents the container holding the codebase
-
Commit: Represents a change of data in the local repo.
-
Tree: Represents the entire history of a repo.
-
Remote: A version of your project hosted elsewhere, used for exchanging commits.
-
Branches: Divergent paths of developement, allowing isolated changes.
-
Main (formally known as Master): common name for default branch
-
Clone: Creates a complete local copy of a repo, including its history.
-
Checkout: Switches between different branches or commits in your repo.
-
Pull: Downloads changes from remote repo and merges them into your branch
-
Push: Uploads local repo changes to a remote repo.
-
Fetch: Downloads data from remote repo without integrating it into your work
-
Reset: Undoes local changes, with options to unstage or revert commits.
-
Merge: Combines multiple commit histories into one.
-
Staging files: Prepares and organizes for a commit.
- Add: Adds changes to file or files bringing them to the staging area for the next commit.
- Commit: Saves changes as a snapshot in the local repo
-
To see the complete documentation follow Links to Git Docs
-
If your in the wild and get stuck use
git help
[command]
main # default level branch
origin # default upstream
HEAD # current branch
HEAD^ # parent of HEAD
Three main ways to clone a repo
- HTTPS
- SSH
- Github CLI
It is possible to clone entire repo or a single branch
git clone [URL] #bring repo from existing repo
git clone ~/old ~/new
git clone --single-branch
git init`
git add my file #add file to repo from local to repo
git add . #add all files
git diff --staged #used after `git add` to review changes to code
git commit -m "Commit Message" # add changes of repo to main branch
git commit -a -m "Com Message" # -a: automatically stages all tracked modified files before commit
git commit --amend # Modifies most recent commit
git commit -m "Initial Commit" --allow empty # Creates empty commit to act as placeholder
git commit -m "Message" --author="name <email@example.com>" # commit with specific author
git push # send local files to remote
git push -u origin # the -u sets upstream branch
git status # check local files to main github branch
git diff [oldid newid]
git log [-p] [file|dir]
git blame file
git show id
git show id:file
git branch # see branches
Can be created through
- Issues tab
- w/ GitHub UI
- w/ GitHub Desktop
- In terminal (below)
git branch # Lists all local branches
git branch [branch-name] # creates new branch
git branch -m [old-name][new-name] # Rename a branch
git branch -d anybranch # with -d anybranch will be deleted
git branch -a # Lists both remote and local branches
git checkout [branch-name] # switchs to branch-name
git checkout -b newbranch # this creates and moves to new branch
git merge # branches together
git pull # get latest changes from branch
git fetch [remote-name] # Fetch updates withour pulling
git apply patch.diff
# Lists all remote repositories along with their URLs
git remote -v
git remote add [name] [URL]
git remote remove [name]
git remote rename [old-name] [new-name]
# Pushes a branch and its commits to the specific remote
git push [remote-name] [branch]
# Pull updates from a remote branch
git pull [remote-name] [branch]
git reset --hard # NOT UNDONE, reset to last commit
git revert branch
git commit -a --amend # replaces prev commit
git log
view log historygit archive
create release tarballgit bisect
binary search for defectsgit cherry-pick
take single commit from elsewheregit fsck
check treegit gc
compress metadatagit rebase
forward-port local changes to remote branchgit remote add URL
register new remote repo for treegit stash
Temporarily set aside changes
- Create new branch
- Add new feature and code
- add, commit, and push changes to the remote
- Get changes reviewed by team member
- Delete remote branch
- Delete local branch
- Pull new code on the remote master to local machine
git checkout -b my-new-branch
# ... make changes to files
git add .
git commit -m "my changes"
git push -u origin my-new-branch
- After pull request complete
git tag 1.0.1
git push --tags
The rest of the notes can be found at my other Repo