
The most basic way to use Git is to use the git clone command to clone an origin Git repository (such as example.git) to a directory on your PC (such as /home/john.doe/git), make a change to a file in the cloned repository on your PC (such as example.txt), use the git commit command to commit the change to the file, and to then use the git push command to upload the file to the origin Git repository.
Branches are used as an isolated way to make changes to files in a repository. A common example would be to create a new branch using the git branch or git checkout command, switch to the new branch using the git checkout command, make a change to a file, commit the change using the git commit command, and then merge the branch to the master branch using the git merge command.
Display the branch you are in
The git branch command can be used to view the shorthand name of the branches in your currently select repo. The wildcard character is used to identify the branch you are currently using (main in this example).
~]# git branch
feature/foo
feature/bar
* main
The --show-current flag can be used to return the currently selected branch.
~]# git branch --show-current
* main
The -v or --verbose flag can be used to include the ID and comment of the latest update in the branch.
~]# git branch --verbose
feature/foo e4df36b moved the validate task and rhel version stuff
feature/bar 3f0dabb Merge pull request #35 from acme/feature/bar
* main 3f0dabb Merge pull request #35 from acme/feature/bar
Display all branches
The -a or --all flag can be used to display all of the branches in the repository.
~]# git branch --all
feature/foo
feature/bar
* main
remotes/origin/HEAD -> origin/main
remotes/origin/feature/foo
remotes/origin/feature/bar
remotes/origin/main
Did you find this article helpful?
If so, consider buying me a coffee over at