Git makes it stand apart when it comes to the branching model.
Let's Quickly Configure the most important and commonly used Git commands for easy reference.
SETUP (once for any new device):
Git for All Platforms install git from https://git-scm.com/downloads
Configuring user information:
-setting a name that is identifiable when we push our changes
git config --global user.name โ[firstname lastname]โ
-set an email address that will be associated with each change history
git config --global user.email โ[adams@mail.com]โ
INIT [for all projects]:
Now that we are all set with the initial requirements let's create a new Directory (Repo) on https://github.com/
Once you Sign in - You will be offered to create a New Repo.
Click on the Button that says New
Add the Repo name, and choose the option to keep it Public (default) OR Private based on your requirements.
Click on Create repository
Create a Folder or Navigate to Project Folder in your Local Machine
- RightClick on/in the Folder and Hit the Option 'Git Bash Here'
- on the Git Bash Terminal enter the below code at a time
git init //to initialize the git repo
git remote add origin https://github.com/user_name/my-repo-name.git
// to link the folder on the local machine with the newly created Git Repo
OR
git clone https://github.com/default_user_name/my-repo-name.git
_Alternatively_
gh repo clone default_user_name/my-repo-name
Note: By Default, the Branch would be set to master
(Optional) If you wish to switch the branch, without committing to master:
git branch -M otherBranchName ex: git branch -M develop
- Now that we are ready with any changes in files of our folder:
git status // to check all our changes (highlighted in red usually)
git add . //to add all the changes
git status // to check all our changes are ready to commit (highlighted in green usually)
- Next, Share a message related to file changes
git commit -m "updates on layout changes"
- Finally, time to make a push
git push
OR
git push origin *branch_name*
ex: git push origin develop
Important: Always take a pull before committing
git pull
OR
git pull origin branch_name