update a fork on GitHub with upstream
git fetch upstream
git rebase upstream/master (sync upstream update to local master branch)
git push (update the fork by push)
Moving a git repository
$ git remote show origin
$ git remote rm origin
$ git remote add origin https://github.com/wubigo/wubigo.github.io.git
$ git remote show origin
$ git pull origin master
Branch from a previous commit using Git
The magic can be done by git reset.
Create a new branch and switch to it (so all of your latest commits are stored here)
git checkout -b your_new_branch
Switch back to your previous working branch (assume it’s master)
git checkout master
Remove the latest x commits, keep master clean
git reset –hard HEAD~x # in your case, x = 3
From this moment on, all the latest x commits are only in the new branch, not in your previous working branch (master) any more.
show head commit and relationship betwen local and upstream branch
git branch -a -vv
(HEAD detached at v0.6.9) 0ad6fa1 update data-plane-api to 4f4ee118c54b7a52393c7d45b94f6bd5040a7118
master 0ad6fa1 [origin/master] update data-plane-api to 4f4ee118c54b7a52393c7d45b94f6bd5040a7118 (#158)
remotes/origin/HEAD -> origin/master
remotes/origin/master 0ad6fa1 update data-plane-api to 4f4ee118c54b7a52393c7d45b94f6bd5040a7118 (#158)
Ignoring an already checked-in directory
git rm -r --cached <your directory>
The -r option causes the removal of all files under your directory.
The –cached option causes the files to only be removed from git’s index, not your working copy. By default git rm
push a new local branch to a remote Git repository and track it
git checkout -b <branch> | git branch <branch>
git push -u origin <branch>
Adding Only Untracked Files
git add -i. Type a (for “add untracked”), then * (for “all”), then q (to quit)
Discard all Changes not staged for commit
git checkout – .
Create a new empty branch and import from svn
git checkout --orphan <branchname>
git rm --cached -r .
svn checkout
git add .
git commit -m "backup from svn tag"
git push --set-upstream origin <branchname>
save username and password in git
git config credential.helper store
then
git pull
~/.git-credentials
I delete a Git branch both locally and remotely
Executive Summary
$ git push -d origin
$ git branch -d branch_name
or use:
$ git branch -D branch_name
As of Git v1.7.0, you can delete a remote branch using
$ git push origin –delete
git without proxy
method 1
$ env|grep proxy
http_proxy=http://192.168.0.119:3128/
socks_proxy=socks://192.168.0.119:3128/
https_proxy=https://192.168.0.119:3128/
$ unset http_proxy
$ git pull
method 2(proxy for certain git urls/domains)
@web:~/workspace/git/pub$ cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[http]
proxy = ""
[https]
proxy = ""
https://www.andrewpage.me/tracking-down-bugs-with-git-bisect/ https://medium.com/@fredrikmorken/why-you-should-stop-using-git-rebase-5552bee4fed1
check the list of tags on the upstream repo without cloning or fetchingn
git ls-remote https://github.com/go-delve/delve
git ls-remote --tags https://github.com/go-delve/delve
the difference between origin and upstream on GitHub
- upstream generally refers to the original repo that you have forked (see also “Definition of “downstream” and “upstream”” for more on upstream term)
- origin is your fork: your own repo on GitHub, clone of the original repo of GitHub
From the GitHub page:
When a repo is cloned, it has a default remote called origin that points to your fork on GitHub, not the original repo it was forked from.
To keep track of the original repo, you need to add another remote named upstream
git remote add upstream git://github.com/user/repo.git
You will use upstream to fetch from the original repo (in order to keep your local copy in sync with the project you want to contribute to).
git fetch upstream
(git fetch alone would fetch from origin by default, which is not what is needed here)