About Git

Git is a distributed version control tool, designed to handle everything from small to large projects. Git is the system we use to track changes. It's a filesystem that keep a lookout for changes in the files, including who made each change and why they made it.
Git help us:
1. Track document versions.
2. Keeps an history of document changes.
3. Encourage team work.

Github

While git is about keeping track of changes in code, GitHub.com is a cloud service that helps teams in communication, collaboration and project management.
Github repositories can be private or public. Only the owner and collaborators can view or contribute to a private repository while public repositories are visible to everyone. With that said, you should be careful of what you publish on your public repository.

Commands

git commit -m "bug-fix"

Commit changes with a message within the quotes

git init

Initialize a local Git repository

git status

Checks and describes the state of the current repo

git pull

Update your local repository to the latest commit, for exampel from Github

git push

Push the changes to remote repository, for exampel to Github.

git branch

List all the branches and marks the current branch

git add .

Adding all the files to the staging area

git rm -r "file-name.txt"

Remove a file or a folder with the specific name

git diff

list the changes that have been made

git fetch

git fetch is the command that says "bring my local copy of the remote repository up to date." (git pull does a git fetch followed by a git merge)

git push origin [branch name]

Push a branch to your remote repository

git push -u origin "branch name"

Push changes to remote repository and remember the branch

git log

View the changes, the different commits, commit-number, author and date

git checkout -b "branch name"

Create a new branch and switch to it

git checkout master

Switch branch to masterbranch

git checkout "branch name"

Switch to a branch by using the branchnamne

git add -A

Adding all new and changed files to the staging area

git add "file-name.txt"

Adding a specific file to the staging area

touch index.html

Creates a file with the name "Index.html"

git clone "url"

git clone is used to clone an existing remote repository(often shortened as "repo") into your computer

git merge "branch name"

Use git merge when you whant to merge a branch into the active branch

Work with git

Get started with git

if you don't already have git installed you can start by installing it by pressing the orange git-symbol above. When you have Git installed you can open the terminal and check if it's there by using the command:

"git --version"

The next step is to create a new repository. click on , followed by clicking on "New repository"

Name your repository. For exampel, I have named my repository for this project to "git-project". Then choose if you want to make the repository either public or private.

Select Initialize this repository with a README before pressing create repository.

and there you have a new git repository.

If you whant to download an existing remote repository you want to run the command:

git clone "Web URL"

Add & Commit

You can add your changes to the staging area by using the "git add"-command, more examples of the "git add"-command can be seen above followd by the headline "Commands".

The picture below shows a more clear picture of the different stages between your working directory and remote repo

Branches

A good way to keep track on your different features when you're working in git is by using different branches for each feature, it keeps the features isolated from each other. The "default" branch when you create a repository is the master branch. You use the other branches for development and then merge them back to the master branch when the feature is complete.

An advice is to name the branches related to each features. This helps you if you want to go back and make a change later on is that specific feature.

Merge

In Git, "merge" is when you integrating another branch into your current working branch. You're using your changes and combine them with your current working files. It's easy to merge in git, you just have to use the command:

git merge "and-the-branch-name"

This means that you will merge the branch that you are currently in with the branch inside the quotes. And git will figure out how to integrate new changes successfully... most of the time.

Conflicts

Git is not always perfect and can become a bit complicated if two poeple are working and changing in the same file. Conflicts are most likely to happend when working in team.

A conflict shows when more than one person has made changes in the same branch and made edits on the same line or something has been edited in one branch and deleted in the other.

If this happends, git will mark the file as having a conflict - which you'll have to solve before you can continue. It can look something like this:

This will leave you with the option to choose between:

"Accept Current Change".
"Accept Incoming Change"
"Accept Both Changes"
"Compare Changes"

Keep calm and carry on.