Interact with local Git and GitHub
You want to learn, how to interact Git and GitHub locally so that
- You can modify GitHub file on your computer
- Update your remote repository on GitHub throgh local git
Let's dive into learing......
(*Note: Requirement:
- Knowledge of how to create account on any online platform
- Installed git on computer (if not go through website link: https://git-scm.com/downloads
- Introduction of git software commands (Command cheatsheet URL: https://github.github.com/training-kit/downloads/github-git-cheat-sheet/ ))
*Steps you need to follow:
- Create account on GitHub (Fill information)
- Create new repository
- After successfuly creating new repository click "Clone or download" and copy URL
- Go to your local computer git software and type following command
- $ git clone <"paste URL">
- Git will ask you for GitHub's USERNAME and PASSWORD
- Now we downloaded the clone repository on your local machine
- Computer will automatically create directory and working tree to perform changes in file
- $ cd : To add directory to perform changes
- Now use your command on git to perform actions ( For more information on commands check this URL: https://github.github.com/training-kit/downloads/github-git-cheat-sheet/ )
- After you made changes repository on your local machine you need to update those on you GitHub remote repository
- $ git push : Use to merge changes on GitHub repository (It uses Fast-forword merge to merge changes )
- Now you successfuly updated the GitHub remote repository
*Updating the local repository
- After that you made some changes on the remote repository on Github and you want to retrive those changes on your computer you can use next command a. $ git pull ( To fetch and merge changes from Origin/master or Github remote repository to local master branch ) b. $ git fetch ( It downloads remote branches from Github remote repository without merging the content, after we can select which changes to merge) c. $ git remote update ( It fetch changes from remote repository to master without merge )
(*Note: As long as there are no cnflicts, Git will move the current branch tip to the target branch tip and combine histories of both commits.)
*Solving conflicts during merge: When you are tring to push changes to remote repository but your local repository is not updated with Github remote repository
-
$ git push --- this step shows merge conflict aries
-
Now you need to merge locally changes from remote repository use $ git pull ( It automates changes on local repository excluding the lines which contains conflict to do it manually )
-
$ git log --graph --oneline --all ( To see conflict graph representation ) *Note: Above conflict we are going to use Three-way merge to resolve it.
-
$ git log -p origin/master (To see changes made by origin/master and then do edit manually on your editor )
-
$ start notepad++ or Atom <file_name> *Here you have to remove all <<<< or ==== or >>>>> conflict markers and keep lines you want
-
$ git add <fil_name>
-
$ git commit (Here you will see conflict resolved commit on editor, Now you can commit your message on editor to next line.) or $ git commit -m <"your_commit_message">
-
$ git commit -a -m <"your_commit_message"> (shortcut for above to step)
*Extra: To avoid password entering process...
- Use credential helper to store cache for 15 minute
$ git config --global credential.helper cache
$ git pull and it will ask you for userID and password one time after you don't need to type for 15 minutes
- Adding your computer SSH -key to your GitHub account For more information see: https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh
.................................Congrats on your successfuly completion.........................................