2 minute read (207 words).

Must know Git commands for beginners


Linux

Git is a fantastic tool for code change control (I also use it for configuration backups). Below is a list of must know commands which will make your life easier if your new to this version-control system.

## Set Commit User Details
git config --global user.name "NAME"
git config --global user.email "[email protected]"

## Download remote repository
git clone https://URL

## Initiate new repository
git init

## Add remote origin to repository
git remote add origin master

## Pull repository from remote
git pull origin master

## Add files to commit
git add "FILE.txt"

## Commit with message
git commit -m "MESSAGE"

## Push repository to remote
git push origin master

Branches are used to develop new features which can be merged with master upon completion.

## Create branch from master
git checkout -b dev

## Change branch
git checkout master

## Merge branch to master
git merge dev

Noticed an error in a recently commit…

## Undo commit and keep history
git reset --soft HEAD~1

## Undo commit and remove history
git reset --hard HEAD~1
git push origin master --force

## Undo all commits after X
git reset --hard **COMMIT-ID**

There is so much more that can be done with Git and Github provides a fantastic cheat sheet: GitHub Git Cheat Sheet – GitHub Cheatsheets



Share via Twitter LinkedIn Facebook Email