You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Specify a new remote upstream repository that will be synced with the fork
git remote -v
Verify the new upstream repository you've specified for your fork
git fetch upstream
Fetch the branches and their respective commits from the upstream repository. Commits to master will be stored in a local branch, upstream/master
git checkout master
Check out your fork's local master branch
git merge upstream/master
Merge the changes from upstream/master into your local master branch. This brings your fork's master branch into sync with the upstream repository, without losing your local changes
Basic Snapshotting
Command
Description
git status
Check status
git add [file-name.txt]
Add a file to the staging area
git add -A
Add all new and changed files to the staging area
git commit -m "[commit message]"
Commit changes
git rm -r [file-name.txt]
Remove a file (or folder)
Branching
Command
Description
git branch
List branches (the asterisk denotes the current branch)
Discard all local changes to all files permanently
git clean -n
List all untracked files that are to be deleted
git clean -f
Delete all untracked files. Additional arguments: -d for directories, -X for ignored files, -x for ignored and non-ignored files. Can be combined with -f. Usage: git clean -fd, git clean -fX and git clean -fx
Merging, Rebasing & Cherry Picking
Command
Description
git merge [branch name]
Merge a branch into the active branch
git merge [source branch] [target branch]
Merge a branch into a target branch
git rebase [branch name]
Change the base of your branch to what's current in [branch name]
git rebase --continue
Continues rebase after resolving conflicts
git rebase --abort
Aborts the current rebase
git cherry-pick -x [commit hash]
Choose a commit from one branch and apply it onto current one.
Tagging
Command
Description
git tag
View tags
git tag -a [tag_name] -m [tag_desc]
Add a tag to current head
git tag -l
List out all the tags
git show [tag_name]
Get tag - triggered - date - author - commit hash - desc
git push origin [tag_name]
Push tag into origin master
git tag -d [tag_name]
Delete tag
git push origin --delete [tag_name]
Delete tag in remote repository
Branch management
Deleting stale/unused local git branches.
Command
Description
git remote prune origin
Deletes all stale remote-tracking branches. These stale branches have already been removed from the remote repository, but are still locally available in remotes/
git branch -vv | grep 'origin/.*: gone]'
Filter git branches down to those with deleted upstream/remote counterparts