Notes on Git Commands

Local branches

Create local branch

git checkout -b newfeature
git branch -d newfeature
git checkout master  
git merge newfeature
git checkout newfeature
git branch -a

Remote branches

Create remote branch (origin being the remote git host repository)

git push origin newfeature
git push origin :newfeature
git checkout master  
git pull
git branch -r
git checkout dev  
git pull --rebase upstream dev

Manage file changes

Add new file

git add newfile.js
git commit -am "A very nice commit message."
git checkout -- file.js
git update-index --assume-unchanged path/to/file.txt  
git commit -a -m "Commit Comment."
git update-index --no-assume-unchanged path/to/file.txt

Tagging

Create a tag

git tag -a v1.0.0.0 -m "First release"
git show v1.0.0.0
git describe --tags
git push --tags
git push origin v1.0.0.0

Move git repository to a new server host

The best article that I found on how to do this is the Smashing Magazine article.

git fetch origin
git checkout -b develop origin/develop
git remote add new-origin git@github.com:blahblah.git
git push --all new-origin
git push --tags new-origin
git remote rm origin  
git remote rename new-origin origin

Summary

Let me know which other git commands you use on a regular basis.

git diff --name-status master..branch  
git diff master..branch
git log master..branch
git shortlog master..branch

--

--

Passion for Software and Enterprise Architecture. I like to play with Azure, Cloudflare and programming languages (C#, Rust, and JavaScript).

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Cecil

Cecil

Passion for Software and Enterprise Architecture. I like to play with Azure, Cloudflare and programming languages (C#, Rust, and JavaScript).