First steps into git

June 2, 2017 - git

Git is a free and open source distributed version control system you can use with your projects. It also enables you to store your data in the remote repositories like GitHub.

git logo

Before publishing take care of

All you will ever need to know…

Pro Git
…is available for free in this book hosted on git website.

After you will champion the basics I recommend you download GitKraken – this is the tool that will help you visualize what is going on while you type in commands in console and take apart bigger repositories with multiple branches.

Ubuntu installation

sudo apt-get update
sudo apt-get install git

git version

git --version    // git version 2.11.0


git help
git --help
git help command

Global settings

git config --global "Name"
git config --global ""

Review the settings

git config --list

Initialize a Git repository

git init

Add a remote repository or add a new one

git remote add origin
git remote set-url origin https...

Download/fork a repo

git clone

Current state of the project

git status

Start tracking a file

git add FILENAME

Start tracking everything in the current directory

git add .

Add all txt files to the Stage

git add '*.txt'

Update tracking for files that changed names or were deleted

git add -u

Add all new files and updates tracking of files that changed names or were deleted

git add -A

Remove a file or files from staging area

git reset <filename>
git reset HEAD -- .

Put the files from Stage to the Repository

git commit -m "cute octocat"

See commits and past changes – commit hash, author, date, the description

git log

To see more information for each commit, where new files were added or deleted — lists all files

git log --summary

Define location of remote repository

git remote add origin

Push local repository to the GitHub

git push -u origin master

Check changes on GitHub repository and pull down any new changes

git pull origin master

To see what is different from our last commit

git diff HEAD

Use diff to see changes within files that have already been staged.

git add octofamily/octodog.txt

Changes on stage

git diff --staged

Remove the file from stage

git reset octofamily/octodog.txt
git rm --cached FILE

Files can be changed back to how they were at the last commit

git checkout -- octocat.txt

Create a branch

git branch clean_up

Create a branch and check it out at the same time

git checkout -b branchname 

To see all branches

git branch

Switch branches

git checkout <branch>

Remove the files from disc and stage the removal of files

git rm '*.txt'

Auto remove of the files with the commit

git commit -am "Delete stuff"

Commit your changes

git commit -m "Remove all cats"

Switch back to the master branch so you can copy (or merge) your changes from the clean_up branch back into the master branch

git checkout master

Merge changes from branch to master branch

git merge clean_up

Delete a branch (it doesn’t allow you to delete something that hasn’t been merged)

git branch -d clean_up

Push everything you have been working on to remote repository

git push

Change the origin URL (used when the github username is changed)

git remote set-url origin <NEW GITHUB URL>