Git Tutorial

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

If you dont have an empty git repository, You initialize it with: git init.

Then we add the file in a staging area so they can be tracked if changes are made
to them. that is where you decide which file you want to commit, to see the files
in the staging area we say: git status

To add to a staging area so we can track the changes, we use: git add "file(s)".

We then commit it under version control with: git commit -m "message/description".


message helps keep track of the changes made. By convention, you should always use
the present tense in the commit message.

To see the commits you have made: git log

To check the difference in the file, we say: git diff "file".

To rollback to the last committed version, we say: git checkout "file".

To push an existing repository to github, we use:


- git remote add origin https://github.com/yunusa-sanusi/Story.git, add the local
to the remote repo.
- git push -u origin master, pushes the local repo to the remote repo using the "u
flag" which links you local repo to your remote repo. So it pushes the local to a
remote call origin and to the branch called master.

The master branch is the default/main branch of all of your commit.

Gitignore - omitting certain files from your local and remote repo

Branching - Lets say you come up with a new idea and want to try it, instead of
commiting to the main branch, we can create a side branch and starting commiting to
it.

git branch - return all branches you have


git branch "name" - creates a new branch
git checkout "branch name" - switch branch

To merge, go to the main branch and merge from there with this command: git merge
"branch name"

FORKING AND PULLING

forking allows you to copy someone else's repo to your own github account, it is
different from cloning because copy allow you to copy the entirety of the repo to
your local machine. But forking copies it to your account so you can make change
from there as your own repository.

You might also like