The basic concept
There are three areas that Git maintains in your local Repository: Working Directory, Stage(Index), and Repository. There is also a Remote Directory.
Working Directory
: Your working directory where the actual files are stored.Stage/Index
: The cache, also called the staging area, holds your changes temporarily.Repository
: Here is the version that has all the data you commit to, and there is oneHEAD
Point to the results after your most recent submission.
Common Commands
There are only a few commands that Git usually uses, and you don’t need to know them all up front.
Build the warehouse locally
There are two ways to create a local repository:
-
git init
A new Git repository has been created locally
-
git clone [username@host:/path/to/repository]
This is a warehouse from the remote warehouse clone. This is the kind of method THAT I usually use.
Add and Submit
Commands that will be used:
-
Git add
-
Git commit -m "Code commit info"
You can add files you want to commit to the cache by using the git add
command.
Of course, you can use git add. to add all files.
Once added, you can commit the changes using git commit -m “Code commit information”. Now, your changes are submitted to HEAD.
Remember that at this point, the file you want to submit is not in the remote repository.
Push changes
Commands that will be used:
git push
Now that your changes are in the HEAD of the local repository, you can use Git push to commit to the remote repository.
Git push can be thought of as short for Git push origin.
Git push does not specify the name of the remote repository or branch. The default is the origin master
If you have more than one branch, you can replace master with any branch you want to push.
However, if you are using Git Init to create a repository without cloning an existing repository, and you want to connect your repository to a remote server, you will need to use git Remote Add Origin
to push the changes to the server.
branch
Commands that will be used:
-
Git checkout -b [branch name]
Short for git branch and Git checkout.
In general, the above command is sufficient.
Branching is used to insulate feature development. When building the repository, master is the default branch. Work on the other branches and merge them into the main branch when you’re done.
You can use git branch [branch name] to create a branch and use Git checkout [branch name] to switch to the branch. You can use git checkout -b [branch name] to create and switch to another branch.
Use Git push Origin
to push to the remote repository after development is completed in the branch.
Update and Merge
Commands that will be used:
-
Git pull: pull the latest data from a remote repository
-
Git merge
: Used to merge branches
To keep your local repository up to date during development, use Git pull to update your local repository.
If you want to merge other branches into your current branch, use git merge
. Once the merge is successful, you need to perform steps like Git add. to push to the remote repository.
You can use git diff
to see the changes before merging them.
Feel free to point out any inaccuracies