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
Initialize a local Git repository
Checks and describes the state of the current repo
Update your local repository to the latest commit, for exampel
from Github
Push the changes to remote repository, for exampel to Github.
List all the branches and marks the current branch
Remove a file or a folder with the specific name
Undo a commit.
list the changes that have been made
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)
Push a branch to your remote repository
Push changes to remote repository and remember the branch
View the changes, the different commits, commit-number, author and date
Adding all new and changed files to the staging area
Adding a specific file to the staging area
Creates a file with the name "Index.html"
git clone is used to clone an existing remote repository(often shortened as "repo") into your computer
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.