-
Notifications
You must be signed in to change notification settings - Fork 2
Git Guide
This is a quick tutorial on the overall workflow for how to use git.
To clone the repository, use:
git clone https://github.com/UTRA-ART/Caffeine.git
This will give you access to the repository on your local machine. By default, you will be at the master
branch.
When doing development, you will want to create your own branch. You can do this by using:
git checkout -b <branch-name>
Our convention is to specify as CAFF-NUM where NUM is the issue number. Note: the branch is only created on GitHub once the code is pushed (see later sections).
If you want to checkout to another branch without creating a new one, you can do:
git checkout <branch-name>
For example, if you want to go back to master, you can do git checkout master
.
During development, when you make changes that you want to push to GitHub (e.g. the remote repository), you should do the following:
git add <files>
git commit -m "<Useful commit message>"
git push -u origin <branch-name>
The first line will add files that you want to commit. The second file will actually commit those files to your git history. You should use useful commit messages so that we can go back in commits when we need to. The final command will push your code into the remote repository so that they will be stored on GitHub.
You may need to use git for other things. For example, if you want to temporarily store changes, you can use:
git stash
This will stash all your changes and get rid of them so you can do other things. If you want to recover those changes, you will need to do:
git stash apply
or
git stash pop
The former also keeps the reference to the stashed changes (meaning you can apply them again later), whereas the latter will delete the reference (meaning they'll be popped off the stack, so you can't recover them.
During development, you may need to pull changes from other developers or update your branch with master. If you only want to update master, you can do this:
git checkout master
git pull
This will update the master branch and add any new branches that were created to your local repository. If you want to merge changes from master onto your branch, you should do this:
git checkout <branch-name>
git pull origin master
This will pull master onto your branch.
If you are working with another developer who pushed changes onto your branch that you can to pull, you can do:
git checkout <branch-name>
git pull origin <branch-name>
If you need to pull changes from another branch onto your branch, you can also do
git pull origin <other-branch>
You may have merge conflicts, you can resolve manually by editing your file and accepting the changes you want to have / combining them. IDEs, such as VSCode, should provide useful plugins to make this process less painful.
There might be more advanced features that you need from git. You should search things up as they come. Git is a really powerful tool so it probably has the functionality you need.