-
Notifications
You must be signed in to change notification settings - Fork 0
GitHub
Updated: 1/11/19
All instructions will be based on the git command line. For the 2019 year we are implementing a more structured way of dealing with Git and GitHub. Please make sure to follow these instructions and standards when dealing with anything regarding Git or GitHub.
- All branches will be used once and only once per pull request. The moment that you make a pull request and it is merged with the master you must make all changes in a new branch. (more details later)
- All branches will follow the new naming convention:
[User Name]/[Issue Number]/[Issue name] - Issues will be assigned to an individual or a team, they will only work on that until the issue is closed.
- DO NOT make changes, add, or delete files on github.com unless told to do by a software mentor.
- Don't create pull requests if the code is not tested and working. This can be overridden by the Software Mentor.
Listing all branches on your computer:
git branchListing all branches on your computer and remote with more detail:
git branch -aGetting the current status of your local branch:
git statusOpening gitk (gits visual interface):
gitk &Getting a list of all commits (note: to exit press q):
git log --onelineGetting a list of all commits (more graphical)
git log --graph --decorate --pretty=oneline --abbrev-commitLooking for commits that add/delete a string:
git log -S 'Your String'Create a branch from a commit:
git checkout Branch_Name SHA_Of_CommitGet all changes that happened to the local repository:
git reflogMerge changes from another branch (like master or development) with your branch
git pull origin [NAME OF BRANCH]
git pull origin developmentCombining more than one local commit before pushing to GitHub:
git rebase -i HEAD~[NUMBER OF COMMITS]Configuring personal command aliases:
git config --global alias.YOUR_ALIAS COMMAND_TO_RUNWhen you first install git, it is not configured in any way. When you try to do any pushes to Github, it will request your user name and password. Here is how to set those so you don't need to type them in every time.
1. git config --global user.name "Your Username"
2. git config --global user.email your@email.comNow the first time you push it will only ask for your password, and then it will store that for future validations.
When you first start with Github you will need to clone the repository from the cloud to your local machine.
- Go to the repository, the link is here.
- You can then click on
Clone or Downloadand copy the link.https://github.com/frc6995/Robot-2019.git - Navigate to the folder in which you want to put the repository folder.This is done using the command:
Eg:
cd folder/subfolder/repository foldercd Documents/Robotics/Robot-2019 - You will then run the command:
Eg.
git clone https://url.com
git clone https://github.com/frc6995/Robot-2019.git
- Now run this command to move into the new repository folder.
cd /repository_name
Notes on creating branches: Don't go too crazy when it comes to creating branches from branches, but it can be done without consequences.
- Check the issue that you are working on/assigned to and take note of the issue name as well as it's issue number. (Eg.
Task 1 #14) All active issues can be viewed here. - Open git bash or your preferred shell. If you are using the built-in terminal in VS Code you can just go to
Terminal > New Terminal. - Navigate to the folder that contains the repository. (If you are using VS Code it will already be in the correct folder skip to step 4) This is done using the command:
Eg:
cd folder/subfolder/repository foldercd Documents/Robotics/Robot-2019 - Make sure that you are on the branch that you want to branch from, this is an example of creating a branch from master:
git checkout master
- Run a git pull to make sure that you have the latest version of the code:
git pull
- Run git status to make sure you don't have any extra changes that you didn't mean to make.
git status
- Depending on the results of git status:
- If git status returns nothing, continue to step 8.
- If git status says you are ahead of master. Run the command:
git reset --hard origin/master & git pull - If git status says that you have un-committed changes. Run the command:
git stash
- Now create the branch. This is done by running the command: (Make sure to use the branch name format discussed at the beginning of Git Instructions)
Eg:
git checkout -b [Branch_Name]
Take note that branch names CANNOT have spaces. Replace any spaces withgit checkout -b ReaperCrewGreen/14/Task_1
_. - Congratulations you made your first branch. Note that any branch created in this manner will not appear in the cloud until you run your first git push. When you do your first push, run the command:
Eg:
git push --set-upstream origin Branch_Name
Every push after that to the branch can be done with a simple git push:git push --set-upstream origin ReaperCrewGreen/14/Task_1
git push
Once you make a change in the code you will need to stage it. Here is how to do that.
- First run git pull to make sure you are up to date with the branch.
git pull
- Run git status. This lets you view all the changes that have made as well as any that have been staged.
git status
- From there you will see all the changes that have been made.
- Stage those changes:
- If all the changes made are ones you want to keep, run the command:
The
git add ..signifies everything. - If only some of the changes made are ones you want to keep, you will need to run add for each file/folder you want.
For folders
or
git add foldername
For Files:git add foldername/foldername/folder
orgit add filename.example
git add folder/folder/filename.example
- If all the changes made are ones you want to keep, run the command:
- You have now staged all of the changes. You can now commit your work.
Now that you have staged your changes, it is time to commit your work. Committing your changes is the bread and butter of Git. It lets you track all of the changes made as well as revert the repository or branch back to a previous commit.
-
Make sure that you are working on the correct branch. If you aren't, run the below command (This is very important as committing on the wrong branch can be a pain to fix):
git checkout Branch_Name
-
Once you have ensured you are on the correct branch do a git pull to make sure you are using the latest code.
git pull
-
After the pull now you can do your commit. This is done with:
git commit -m "[Your commit message.] - closes #[Issue Number]" -
If when staging changes you did not stage every change available, run the following command; otherwise, move on to step 5:
git stash
-
Now go ahead and either continue editing or push here and now. For instructions on pushing see: Pushing Changes
-
When you want to make another commit just start at Staging Changes and make your way down to Committing Changes.
Pushing changes is what allows others to access the changes you made. In our case we push to github.com.
- You always want to make sure you are pushing your changes to the latest version of the branch. To do this simply run:
git pull
- Now you can push the changes that you have committed. This is done using:
git push
- That is it; all of the changes that you have committed have now been sent to the cloud.
We are using a system this year that requires anyone who wants to push to master to submit a pull request first. Please do not create a Pull Request until your code has been tested.
Here is how to make one for code that you want to have in master.
- Make sure that all your changes have been added and committed to your branch. (Reference previous headers if you don't know how)
- Run the command
git pull origin masterin the branch on your computer and resolve any conflicts if there are any. - Login to github.com and go to the pull requests tab in this year's repository.
- Create the pull request (Make sure to add a comment about the pull request):
- If there is an option to create the pull request from your branch, click on it.
- If there is no bar at the top to create a pull request from your branch, click on
New Pull Request. In the window that comes up make surebase:is set tomasterEg.base: masterand then setcompare:to your branch. Eg.compare: [Your branch name]
- Once the pull request is created you can then assign who you want to review your work (including the whole team is an option).
- Set the label to 'Tested - Passed', indicating that you have tested your code and it works as expected.
- Also add the pull request to the appropriate project (Drivebase changes are added to the Drivebase project).