30
linuxxx
8y

I started hearing about Git about a few years ago (I think I was in the first or second class of my study, am in the fifth now). I understood the concept but found it really hard to work with, as in, so hard that I just didn't use it. It kept coming back again and again and a few months ago I thought: Fuck it.

What is one thing that a lot of devs are good at? Automation, exactly. So, I had a GitLab account (idc about their recent fuckup, will keep using it) and had to keep asking people to set stuff up for me.

I started to do research and stumbled upon the empty repo page from GitLab which provided clear instructions on how to locally do stuff so I could interact with a remote repository. Then I started to bash script.

After one day, I had a fully working bash script which, with just two parameters, initiates a new repo, clones it locally, creates a README.MD and commits + pushes it.
Then I put it as executable in the /usr/bin.

So now, whenever I start a new project, I just have to create a directory, go into that directory and call a command with two parameters and I'm good to go!

Actually pretty proud of that, although it might be the most usual thing for a lot of peoples, I wrote a workaround/automation thingy for the thing I find the hardest in development :).

Comments
  • 5
    Git has SO many features I'm overwhelmed. I only ever constantly use the following commands:

    git clone <url>
    git status
    git add <file(s) | dir(s)>
    git commit
    git push

    More rarely:
    git rm <file(s) | dir(s)>
    git commit -a
    git checkout <file>
    git fetch
    git checkout <branch>

    I'm on Linux so I use these terminal commands. On Mac OS, I use the GitHub Mac app which has a nice GUI for all this.

    To init a repo on GitHub I always just use the website to do it, because it's the simplest easiest way. Then, I have a remote I can just clone, commit, and push to.

    These are the most basic commands available and are the only ones I have found useful because my needs are just as basic. Other people are fluent in Git and probably use these and the many more complicated operations.

    Nice work with the bash fu. I would consider doing this for myself if I ever find the need to use the more difficult operations.
  • 1
    I remember when I I was learning got, I decided to make myself a bash script which would commit and push for me. I'd just enter "pushnow" from within the repo I wanted to push, it would show me any new files if I created them, allow me to ignore them, get the comment for the commit, and then push. I was pretty proud of it when I made it, but now I haven't used it in ages.
  • 1
    I find myself using git checkout -- . When I think "what was I doing?!"

    But yeah, when you have git nailed down it will really improve your development flow 😁
  • 2
    I never even considered writing a script to automate repo creation. Great idea!
  • 2
    @jjhiza I do it using gitlabs api :)
  • 0
    @linuxxx, I've never actually used GitLab as I find it a bit redundant. Are there any discernable differences and benefits to using it versus Github? I'm always looking to add to my skill set.
  • 1
    @jjhiza GitLab is meant for local teams. At my workplace, we've set up GitLab Community Edition, it holds the project's remote repo.
  • 1
    @cst1992 Is it literally just meant for local teams? I also use it with remote devs really and that works great
  • 1
    @linuxxx The joy of making something is what we devs live for :)

    Glad you're having fun with your script. I'd suggest slowly learning more commands as you get comfortable. I find the technique that works for me is to simply use it on real projects.

    Like @corscheid, here's my list of commands(from most common to least)

    git status
    git add
    git commit
    git log
    git checkout
    git stash
    git push
    git diff
    git merge
    git fetch
    git rebase(normal and interactive, with -i parameter)
    git pull(yes, I use fetch-merge instead of pull)
    git clone
    git remote
    git cherry-pick
    git rm
    git config
    git rev-parse
    git gc
    git credential-store(I know, but entering passwords gets monotonous after a while)

    That's almost all the commands I know(It's almost impossible to know them all anyways, since there are over 150 of them). But the above are enough 99% of the time. Rest of the time there's SO :)
  • 2
    @linuxxx BTW, similar to you, I also have a Bash addon(mostly to avoid having to type trivial Git commands again and again). Here it is:

    https://github.com/chaitanyathengdi...

    Might find it useful, might not.
  • 1
    @linuxxx I assumed it's for local teams, since our version doesn't have pull requests; rather, merge requests are there. IDK, could be that that's only for the GitLab CE.
  • 0
    No one can use git without making bash scripts! I've gone so far as to make a wrapper around the git cli entirely:
    https://github.com/wmhilton/g Even if you don't use it, the README doubles as a great git cheatsheet.
  • 0
    Will also throw out there that the free Go Git Service is awesome. It was so easy to install, every other open source tool pales in comparison. Definitely consider it as alternative to Gitlab. https://gogs.io
  • 0
    @wmhilton I'll have a look, thanks!
  • 0
    @cst1992 Gitlab lets you create more than one private repository. There are some more features than github is still missing.
  • 0
    @elaptron I have a shit ton of private repos on my GitHub. I either misunderstood your point or it is invalid.

    Welcome to devRant btw :)
  • 1
    @jjhiza Its primary self hosted... And it has a ton of more features, tiny things that make a huge difference. GitHub looks a bit toish against it IMHO
  • 0
    @wmhilton Yeah but its only lightweight. If you want to enforce a real workflow, its better to use the big one. For just storing and sharing gogs is better :)
  • 0
    @vortexman100 that makes sense
  • 0
    @wmhilton I think i will setup gogs or its fork gitea tomorrow. I have GitLab EE on the server and dont want to pay for other users like friends... Also handy for projects that dont justify the big one...
  • 1
    @yarwest correct me if I'm wrong, but as far as I know, github requires a payed plan for private repositories. Gitlab offers them for free. Don't misunderstand me, I don't have a problem with paying for great services, but at least, it's a difference.
  • 0
    @elaptron Oh that is what you mean! Yeah that is true and it is an advantage. I myself have the Github student license so I don't have that problem.
  • 0
    @elaptron Github provides one free private one, gitlab unlimited.
  • 0
    @linuxxx yeah he mentioned that before, when did they start offering the one free one? I don't remember having that 1.5 years ago.
  • 0
    @linuxxx I mean come on. Most repositories are under 1 MB, 1 TB drive suffices for a shitload of users... That really shouldnt be a problem.
Add Comment