BLACK CAT PROGRAMMER

git notes

Show current branches

the * denotes all the local branches
-a to show remote branches as well

git branch

Normal workflow:

git clone <path of the respository<
<add your change>
git add *
git rm <the build or libraries that added accidentally>
git commit -m "comments~~~"
git push

Fetch

Downloads new data from a remote repository – but it doesn’t integrate any of this new data into your working files. Fetch is great for getting a fresh view on all the things that happened in a remote repository.

git fetch

# remove any remote tracking branch
git fetch -p 

Pull

Update your current HEAD branch with the latest changes from the remote server. This means that pull not only downloads new data; it also directly integrates it into your current working copy files.

git log --oneline

# show remote branch log without checking out the branch
git log origin/<remote branch name>

Delete branch locally and remotely

# show local branch
git branch

# delete branch locally
git branch -d <branch name>

# delete branch remotely
git push origin --delete <branch name>

View git log

git log --oneline

# show remote branch log without checking out the branch
git log origin/<remote branch name>

Revert last commit

git reset --soft HEAD~1

git reset --hard HEAD~1
# hard will not preserve the change

Set and unset proxy

git config --global https.proxy http://127.0.0.1:1080
git config --global https.proxy https://127.0.0.1:1080

git config --global --unset http.proxy
git config --global --unset https.proxy

Roll back to pushed commit

git checkout <branch name>
git reset --hard <last needed commit hash>
git push origin +<branch name>

Reference
https://www.git-tower.com/learn/git/faq/difference-between-git-fetch-git-pull
https://git-scm.com/docs/fetch-options/1.7.1

Posted in notes