A repo to introduce those new to collaborative development on git
- Check if Git is already installed on your Ubuntu
git --version
- If not
sudo apt update
sudo apt install git
- Create a GitHub account
- Create a repository on the website, or find a repository of interest to which you have collaborative access as follows.
- Click on the green button drop-down saying Code
-
Create an SSH key if prompted, following these for instructions
-
Links for SSH key generation
Generating a new SSH key and adding it to the ssh-agent - GitHub Docs
-
After generating an SSH key copy the link in SSH column of Code dropdown
-
Clone the repository as follows
git clone [email protected]:rohankalbag/github-intro-repo.git
Aside: make sure to star a repo whenever you clone it to show your appreciation to the developer
- you should see something like this
- enter the repository directory, to make a dummy commit onto the main branch do the following see the following code next (not recommended however), development should generally done on branches and later merged into main
- the above changes will be held locally to push it to the GitHub remote upstream do the following
How to work on branches
- I will create a branch for my commits in a branch called
rohan
- I will make a change in
intro_logs.txt
and make a commit
- This pushes the changes only to the
rohan
branch on the repo and doesn’t modify the main branch
- how to check progress of someone else’s work on a different branch, if you are in a collaborative team ?
git switch that_branch
git log
-
What if you want to merge your changes onto the main branch without any conflicts? (very important so pay attention :D)
- Just for an example I will make some changes on the main repo by adding something to the
./readme.md
file on the remote and I have to make sure to take that change into my branch before making a pull request. Added the orange line for example
- Now there is a change on the remote which I don’t have locally so I should be careful to consider it
#this is important to prevent conflicts git merge origin/main # a pop up might come here asking for commit message, exit the window with ctrl + x git push
- Just for an example I will make some changes on the main repo by adding something to the
Time to create a pull request
- Open your GitHub repo, and click on compare and pull request
- click on create pull request
- you can assign your teammates as reviewees just to make sure before merging
- if you have discussed and you are ready to merge this into the main repository then click/ask your teammates to click on merge pull request and we are done.
- your changes would now reflect on the main branch of the repo, congratulations you have successfully made your first successful contribution.
- If you need some more info, always use Stack Overflow, ask people around you or check Git documentation online/the man page
man git