-
Notifications
You must be signed in to change notification settings - Fork 2
Git From Scratch
Git is the most popular version control system(vcs) for code and GitHub enables developers to host their git repositories on the internet to share and collaborate with others.
On IRIS, we use Git and GitHub in 4 different ways:
- Sharing code between team members
- Keeping track of different versions of the code
- Managing tasks using the GitHub Issues and the kanban boards from GitHub Projects
- Documenting important resources/setup information/etc. with GitHub Wiki
The basic cycle of using Git/GitHub would be:
Cloning a git repository --> Editing the code --> Staging files --> Making a Commit --> Pushing updates to a remote repository --> Continue editing
Cloning downloads a remote repository (hosted on services like GitHub) to your local filesystem.
- Go to the home page of a repo and click on the green icon
- Copy the https or ssh url depending on the type of authentication you are using
- In a terminal:
git clone <copied url>
- Ex.
git clone https://github.com/IllinoisRoboticsInSpace/IRIS-2022.git
- You may need to download git here
- Ex.
Now, you have a local copy of your code to test and make changes to. TODO: Handling Merge conflicts
Staging allows you to choose which files to commit to git after you have made some edits to your code. Staging is useful since you may not always want to commit all of the changes you have made to your repository.
- Adding certain files/paths in your repo:
git add filename1 filename2 folder3/
- Adding all the files in your repo:
git add .
- A good practice is to use a
.gitignore
file to ignore certain types of files that don't need to be a part of the code base, like build/log files or large data files -
git status
will also show which files you've edited, and which ones are currently staged
Committing saves a snapshot of your code. All the staged files from git add
will be saved as a snapshot.
git commit -m "A commit message summarizing the updates"
- Amending a previous commit (with new staged files or a new message):
git commit --amend -m "Amended commit message"
The last step after making some commits in your local git repo is to push your updated code to the remote repository so other developers can get the updates you made.
git push
- If you have multiple remote repositories, choose the specific one:
git push origin remote_name
- Creating a new local branch:
git checkout -b new_branch_name
- Pushing the new local branch to a remote:
git push -u origin branch_name
- Pushing the new local branch to a remote:
- Pulling a remote branch locally:
git checkout --track remote_branch