This is the follow-up article of Git Simplified: A Beginner guide to git and GitHub
. In that article, I have explained basic git terminologies, workflow, and some basic git commands from initializing a project on your computer/laptop to publishing to Github. If you are a beginner I will highly recommend you to do check it first.
Working in a team and maintaining a code base and tracking the changes of each and everyone manually is hard(and a terrible choice). This is just one of many ways to collaborate on a project using GitHub. But it’s one I would suggest if you’re just starting out working with a team and haven’t established a git-flow yet or know where to start in establishing one.
Most of the time if you working on a large-scale/open-source project you don't have write access to the code. for working on your desired project first you have to fork the project into your remote repository.
Now first fork a project. what it does is create a copy of the original project into your repositories.
Now clone a repository into your local machine.
git clone <remote repo link>
And if you forked the repository and you don't have write permission there is another step you have taken.
git remote add <remote name for source repo> <source repository clone link>
When you are working in a team you are required to update your local copy with the changes your partners/colleagues have made.
git pull <remote name> <branch name>
- Fetch the changes from remote repositories and store them in your local repository.
- Marge those changes store in your local repository with your working directory
You can achieve the same result in two different steps with!
git fetch <remote name> <branch name> git merge <remote>/<branch>
As we know git tracks all the changes you have made. If you want to compare your changes in working directory with staging area, local repository or even you can compare your changes with two different branches in git with git diff command.
Let's take an example from our previous task when we fetched the data from the remote repository in our local repository.
For this purpose, I have made a repository git-test in my GitHub and cloned that repo in my local machine.
git clone https://github.com/shahabbukhari/git-test.git
After that, I made some changes in README. MD file remotely. now i will fetch the changes
git fetch origin master
git diff origin/master
- In 1st line
diff --git a/README.MD b/README.mdwhere
b/README.mdare the versions of the file in which changes are made
a/README.mdis the version of README. MD file present in your working directory and
b/README.mdis the version of README. MD file present in your Local repository.
- In the last two lines starting with
-. Which usually means
+line is added
-line is removed but as we are comparing
a/README.md(working directory version) with
b/README.md(local directory version). Now it's showing we have removed
-# git-test -This I have made this repository to show the implementation of git diff method.lines because they are present in the local repository but not in the working repository.
git diff is a multi-use Git command that when executed runs a diff function on Git data sources. These data sources can be commits, branches, files, and more. for complete understanding check this Guide.
After adding and reviewing changes now it's time to submit your code back to your own repository(which is a copy of the original repository).
git push <remote name> <branch name>
After Creating changes to your remote repository now you need to create a pull request to be able to merge your code with the source repository where the maintainer/owner will merge your code with the original repository after reviewing it.
Congratulations, if you read the complete article and stick till the end. For practice used my git-test repository. fork, clone, make changes, push and create a pull request