In the root directory of the project you want to have version control, type the following:
git init
This is a one time thing. After you initialize the repo, you won't have to do it again.
When adding new functionality, create a branch with the following command:
git checkout -b your-branch-name
This will create a branch off master
or main
that you can work on.
Once you're ready to commit work to the branch, type the following:
git commit -m "a short commit message here re: what was done"
Once you're done implementing functionalty on your branch, you're ready to merge it into master
or main
. You do that as follows:
git checkout master
orgit checkout main
, depending upon what your root level branch is called.git merge your-branch-name
The first command checks out master
. The second command merges your-branch-name
into master
.
To figure out which branches you have, you can type the following commands:
git branch
To exit out of the branch list, just type q
for quit
To delete a branch, type the following:
git checkout -d your-branch-name
All commits have a hash mark assigned to them. To get a list of commits, type the following:
git log
Typeing that out will give you a list that looks something like this:
commit ecefc1d0bfda09b0c00fbe7f243f27692ce7ccd3 (HEAD -> wValidator)
Author: AdrianBinDC <[email protected]>
Date: Fri Jun 18 20:59:13 2021 -0400
Updated team acronym
commit adcd77af73473cb4d40c46c4105b3a518b6654ab
Author: AdrianBinDC <[email protected]>
Date: Fri Jun 18 20:57:55 2021 -0400
Added new maintainer to README.md
commit 3574ab377c371cb73dd16397f73e776354cb5af7
Author: Will <[email protected]>
Date: Mon Jul 3 16:28:46 2017 +0700
Whoops—didn't need to call that one twice
commit 43d6f24d140fa63721bd67fb3ad3aafa8232ca97
Author: Will <[email protected]>
Date: Mon Jul 3 16:24:13 2017 +0700
check05: Finally, we can return true
commit bf3753e4c693f45610f06084587b0c1631df9ac9
Author: Will <[email protected]>
Date: Mon Jul 3 16:23:47 2017 +0700
The commit <commit hash with a bunch of jibberish>
message tells you what the commit hash is. To get a particular commit and put it on another branch, you can just get the commit hash, go to your branch (git checkout branch-you-want-to-be-on
) and type:
git cherry-pick ecefc1d0bfda09b0c00fbe7f243f27692ce7ccd3
.
This should be enough for you to get the basics of git. As you progress or run into issues, you can Google them to fill in the blanks.