GIT – KICK OFF AND USEFUL WORKFLOW
In this tutorial, you will see how to start and follow up a project published on a git repository.
First of all, if you don’t have git installed on your local system, install it with
sudo apt-get install git
Then, we are going to assume that we have a project called “Offset101”.
We have two different ways to start working on:
Fork the project
- Let’s go to your project github repository, and make a fork to your own repo.
- Create a new directory where you will alocate your local project copy and do the following process:
12345678910111213 cd /project-pathgit init# Set up your local repository# Another way to do so, its via https# https://github.com/<your-github-username>/<Offset101.git>git remote add <origin> ssh://email@example.com/<your-github-username>/<Offset101.git># Set up your remote repository# Another way to do so, its via https# https://github.com/<owner-github-username>/<Offset101.git>git remote add <remoteOwner> ssh://firstname.lastname@example.org/<owner-github-username>/<Offset101.git>
Note: <origin> and <remoteOwner> are aliases to corresponding repositories.
- <optional> You can check previous configuration with
1 git remote -v
And, you can change them manually on .git/config file.
- Let’s get the code from the remote repo.
1 git pull <ownerRepo> <master>
Note: <master> is the branch that you want to download in order to work on. In some projects its pretty common to use another branch such as develop.
- Once you have the project on your local environment, lets perform the following steps:
12345678 # stand up on the main branch (it's not necessary if you are working on master)git checkout develop# get the lastest version of codegit pull <ownerRepo> develop# Create a new branch for your changesgit checkout -b <task_1234>
- Now you can make whatever you need, and start working on the code itself. After that, you will need to push those changes to the repository:
1234567891011121314151617181920212223242526272829 # Check current status, and all files you are about to commit.git status# You need to add all those files you have modified.git add /files-paths#git commit -m "Any descriptive information of your changes"# Return to the develop branch to bring up any changes someone else could make on the project# This is not necessary if you are the only one working on.git checkout developgit pull ownerRepo develop# Return to your branch, without the "-b" argument, because you don't need to create again the branch.git checkout task_123# Merge the last changes you pulled on previous step# This is not necessary if you are the only one, or if you did not brought up any change.git merge develop# git by itself could make the merge automatically, but, if any conflict appear# you will need to fix it manually, add the changes, and commit them.# If everything went well, lets push your changes.git push origin task_123# Return to the develop branchgit checkout develop
- After pushing your changes, you will need to go to GitHub, and create a pull request in order to notify the project owner that your changer are ready, and he can merge them to the main branch (in this case, develop).
- Whenever it’s merged, you will be able to pull those changes and get the lastest version.
1 git pull ownerRepo develop
Clone the project
If you are the owner of the project, or even if you have the access rights, you may not need to fork the repository. So, another way to work on, is cloning the repo as follows:
12345678910111213141516171819202122 # Clone from your repository.# Another way to do so, its via https# https://github.com/<your-github-username>/<Offset101.git>git clone ssh://email@example.com/<your-github-username>/<Offset101.git># get code from main branch (it could be develop as well)git pull origin <master># Create a new branch to work ongit checkout -b task_123# check all changed filesgit status# Add all changed filesgit add /files/paths# commit changes to your local repogit commit -m “Descriptive comment of your changes”# upload changesgit push origin task_123