Thursday, August 6, 2020

Git Intro

git - the simple guide



1. Download and Installation
- GO to the link below and download the software. Follow the installation guide.

  https://git-scm.com/download

2. Create a local repository

# mkdir /mygit; cd /mygit
# git init

Create a working copy of local repository
$ git clone /path-to_repo

or if you are suing remote server
$ git clone user@host:/path/to/repository



How it works (Workflow)

Local repository consosts of three tree maintained by git.

1. Your working directory
  - This directory holds the actual files.
2. The index
- This acts as a staging area
3. The HEAD
- it points to the last commit you have made.


Working dir ---Add --> Index (stage) --Commit--> HEAD


Add and Commit

You can propose changes (Add it to the index) using
$ git add <filename> or
$ git add *

This is a first step in basic fit workflow. To actually commit these changes use
$ git commit -m "Commit messages"

Now, the file is committed to the HEAD but not in your remote repository yet


Pushing changes
Your changes are now in the HEAD of your local working copy. TO send these changes to your remote repository, run the following command

$ git push origin master
master is the name of branch. Change it to whatever branch you want to push to.


If you haven't cloned an existing repository and wnat to connect your repository to a remote server, you need to add it with

$ git remote add origin <server>

Now, you are able to push your changes to the selected remote server.


Branching
Branches are used to develop features isolated from each other. The master branch is the "default" branch which you create a repository. Use other branches for development and merge them back to the master branch upon completion.

          feature_x
         ---------------------
branch         /       master        \  merge
-----------/-----------------------\------->

Create a new branch named "feature_x" and switch to it using
$ git checkout -b feature_x

Switch back to master
$ git checkout master

Delete the branch you created
$ git branch -d feature_x

a branch is not available to others unless you push the branch to your remote repository.
$ git push origin <branch>



Update and merge
To update your local repository to a  newest commit, run
$ git pull

In your working directory to fetch and merge remote changes

To merge another branch into your active branch (say master), use
$ git merge <branch>

In both cases git tries to auto-merge changes. Unfortunately, this is not always possible and results in conflicts. You are responsible to merge those conflicts manually by editing the files shown by git. After changing you need to mark them as merged with
$ git add <filename>


Before merging changes, you can also preview them by using
$ git diff <source_branch> <target_branch>










http://rogerdudler.github.io/git-guide/



No comments:

Post a Comment

Git branch show detached HEAD

  Git branch show detached HEAD 1. List your branch $ git branch * (HEAD detached at f219e03)   00 2. Run re-set hard $ git reset --hard 3. ...