All about git from where you are
Say you just cloned a git repo and you want to make to make a branch.
Normally, you’d have to clone the repo, move into the branch then make the branch.
The above workflow would be as follows
git clone super-awesome-project
cd super-awesome-project
git checkout -B super-awesome-branch
.
All the above is cool and very explicit. However, when you are automating such a workflow, it can be very confusing where in the system path you are especially if lots of git commands are being used.
To curb this confusion, git -C is here to help.
The above workflow can be made to be as follows with our newly discovered tool.
git clone super-awesome-project
git -C super-awesome-project/ checkout -B super-awesome-branch
Pretty neat, right?
This can be expanded to include lots of other git commands as below
date > super-awesome-project/current_date.txt
git -C super-awesome-project/ add current_date.txt # does git add
git -C super-awesome-project/ config user.name dummy_name
git -C super-awesome-project/ config user.email dummy@email.com
git -C super-awesome-project/ commit -m "We are here and we made it" # git commit
git -C super-awesome-project/ push --set-upstream origin super-awesome-branch -o merge_request.create -o merge_request.target=main -o merge_request.description="Something we found out" -o merge_request.draft #git push with merge options (Gitlab)
To learn more about git -C have a look at its documentation here .
Leave a comment