Git & Github hero-section

Step#1 Git Repository

Follow these steps :

  1. Log in your github account at any brower.
  2. To make a git repository, do as shown in the picture:
  3. Click on "+" sign and click "New repository"

This is how we can add a git repository to our account...

Step#2: Make a Git Repository

Follow these steps :

  1. Enter Name of Your Repository
  2. Click on create repository button

Following picture will be your first page of repository

Step#3: Make a Local Repository (git init)

Follow these steps :

  1. Create an empty folder
  2. Open VSCode
  3. Open Terminal
  4. Type 'git init'

Following message should be displaye on the terminal

Step#4: Add some files in folder

Follow these steps :

  1. Add some files
  2. Write some code in it

Check Picture for help

Step#5: Check status of added files (git status)

Follow these steps :

  1. Open Terminal
  2. Type "git status"

Following picture show the status of your files for now they are untracked.

Step#6: Add these files to local repository (git add .)

Follow these steps :

  1. Open Terminal and type "git add ."

Following picture show the status of your files after performing the git add command

Step#7: Add files to local git server(git commit -m "message")

Follow these steps :

  1. Open Terminal
  2. Type "git commit -m "message""

Now files that you have added are in local git server on your computer

Step#8: Add files to global git server

Follow these steps :

  1. Open global git repository that we have created previously on github
  2. Check all the commands already written there
  3. Add origin using url to repository
  4. in our case "git remote add origin https://github.com/IsmaeelMughal/LearnGit.git"
  5. use "git push -u origin main" to push all the files to the global repository

Now files that you have added are in global git server on your github account

Step#9: Check your global repository for files

Follow these steps :

  1. Open Your repository that you created
  2. In your browser enter url or click on the link present in the terminal of VSCode

now you can see your files uploaded there

Step#1: Creating a branch

Following steps shows hot to create branches with different methods :

  1. Open your terminal
  2. Run : "git branch 'branchname'" OR
  3. Run : "git checkout -b 'branchname'"

The difference is 'git branch' command only create new branch but 'git checkout' create and switch to that branch

One Branch to another

Following steps shows you how to switch:

  1. Open your terminal
  2. Run : "git checkout 'branchname'"
  3. In our case "git checkout newBranch"

now type 'git branch' to see the current branch

Delete a branch

Following steps:

  1. Open your terminal
  2. Run : "git branch -d 'branchname'" OR

Check the output:

Step#1: Copy URL

First of all we have to copy the url of the repository from where we want to clone data. Follow the steps:

  1. Open Repository from github
  2. Click on 'code<>'
  3. Copy the url from there

For help see the pic!

Step#2: git clone

Open VSCode and Follow steps:

  1. Open Terminal
  2. Run 'git clone "URL"'
  3. In My case 'git clone https://github.com/IsmaeelMughal/LearnGit.git'

For help see the pic!

Merge

Let's say you have two branches and different work on both branches then you may habe to merge your work in a single branch. Follow steps for better understanding

  1. Open VSCode
  2. We already have master and newBranch
  3. switch to newBranch
  4. Make some changes
  5. Get back to master
  6. type 'git merge newBranch'

Don't Forget to come back to master branch for merging our command merge newBranch changes with master branch

Don't Forget

Steps you need to Remember!!!

  1. On secondary Branch you must add and commit chnages
  2. To merge with master branch you mut be on the master branch
  3. switch from secondary branch to master
  4. then type 'git merge newBranch'

See Picture for help!!

Merge Conflict

In some you may incounter such condition..

  1. A person make chnages in master branch on a line
  2. 2nd person working on the same project on another branch make changes on the same line
  3. In such cases merge conflict occures

See Picture for Better understanding!!

Solution to Merge Conflict

You can choose any of the case

  1. Accept current change
  2. Accept Incoming Change
  3. Accept Both chnages
  4. Compare chnages
  5. In my case I choose both changes

See Picture for Better understanding!!

git pull

The git pull command first runs git fetch which downloads content from the specified remote repository. Then a git merge is executed to merge the remote content refs and heads into a new local merge commit. To better demonstrate the pull and merging process let us consider the Picture

  1. Open VSCode
  2. make sure your repository is connected with github
  3. type 'git pull'

Pull request was successfully made!!! If we had some chnages on global repository we could chnage that using pull or implement in our repository