Skip to content

Instantly share code, notes, and snippets.

@sambatlim
Last active April 26, 2021 09:24
Show Gist options
  • Save sambatlim/89185b0df478a3b59a793584cc55cd63 to your computer and use it in GitHub Desktop.
Save sambatlim/89185b0df478a3b59a793584cc55cd63 to your computer and use it in GitHub Desktop.
useful command to update your forked repository to the original repository you forked from.

commands to update our forked repo to the repo we forked from.

To add upstream repository
git remote add upstream [github repo that your forked from] 
To check the origin repo and upstream repo
git remote -v 
Fetch everything from upstream repo
git fetch upstream 
Check branch in your local repository
git branch 
If you are not in master(the branch that you want upstream/master merge to), please use command below to switch to master.
git checkout master 
Start merging the upstream master branch to your local master branch
git merge upstream/master 
add everything that have been changed after merge to push to your remote repo
git add . 
add commit message
git commit -m "update from upstream repo" 
push to master branch
git push -u origin master

Additional

1. create new branch in your local repo
git branch new-branch-name 
2. switch to that branch
git checkout new-branch-name
command below equal 1 + 2
git checkout -b new-branch-name 
to pull unrelated history
git pull --allow-unrelated-histories
I accidentally committed to the wrong branch. How do I delete that commit?
git reset --hard HEAD~1 
I want to reverse one commit
git revert head 
I want to see the status
git status 
Log one file
git log --oneline --graph 
I want to save my current change without making the commit and swith to head.
git stash
I want to config username and email
git config --global user.name username
git config --global user.email [email protected]
How to delete branch locally and remotely?
// delete branch locally
git branch -d localBranchName

// delete branch remotely
git push origin --delete remoteBranchName

// force delete
git branch -D localBranchName
Rename the local "master" branch to "main"?
git branch -m main
To ignore your recently edited file.
git checkout HEAD -- my-file.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment