Last Updated: July 27, 2016
·
709
· ohmmho

Git Basic Commands

As a frontend web developer, I have to use GIT everyday to share and manage differents code versions. When I started learn GIT, I also wanted to lose fear from the command line, so that's why I never used GUI like SourceTree and try to improve my command line skills everyday :D

So here come my most used GIT daily commands.


To create new branch and checkout to it:

git checkout -b [BRANCH]

To checkout to your last visited branch:

git checkout - 

To grab just a file from other branch without checking out:

git checkout [BRANCH] -- path/to/file.scss

To rename a branch:

git branch -m [NEW NAME]
#if you only specify a branch, you apply changes on your current branch
git branch -m [BRANCH] [NEW NAME]

To ignore changes on a tracked file:

git update-index --assume-unchanged [FILENAME]

To merge branches:

git checkout [TO BRANCH WHERE YOU WANT TO MERGE]
git merge [THE OTHER BRANCH]

To solve conflicts on a specific file, use --ours or --theirs:

git checkout --ours path/to/file.scss
git checkout --their path/to/file.scss

Then add and commit the files :)


To go back when a merge generates too much conflicts:

git merge --abort

Show merged and no-merged branches:

#Shows branches that are all merged in to your current branch

$ git branch --merged

#Shows branches that are not merged in to your current branch

$ git branch --no-merged

Git aliases [from https://git-scm.com/book/en/v1/Git-Basics-Tips-and-Tricks]

git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status

and updating....


http://papadako.github.io/git-a-little-tale/
https://github.com/blog/2019-how-to-undo-almost-anything-with-git

2 Responses
Add your response

Nice mate, I wonder how i could stop using git since I discovered it... ! Very powerful tool... I use the same comands and of course git pull & git push which are really usefull ones if you have to share your code. Thanks for the tips and hope it can helps others to use this magic tool =D

over 1 year ago ·

hey @seoshake, thank u so much for ur feedback, yes I hope it helps others to use Git and also to share our best commands :D

over 1 year ago ·